how to check method calling in rspec
rubyrailsrspec
tomoyukikashiro
You can check a method is called or not by using receive
in rspec.
describe "#method" do
it "should call method_b" do
@user = Persion.new
expect(@user).to receive(:method_b)
@user.method # method_b is called in method
end
end
- You should call
receive
before method_b is called - You can specify call count
expect(@user).to receive(:method_b).once
expect(@user).to receive(:method_b).twice