RSpec allows stubbing a potential request as follows -
expect(@project).to receive(:msg).at_least(n).times
What about situations where I don't know (and don't care) how many times @project receives :msg.
Is there an "unlimited" stub in RSpec that tells it to always stub it for that example no matter how many times its called?
You can use allow if you don't care how many times it gets stubbed.
allow(@project).to receive(:msg)
Using allow(@project).to receive(:msg) (as suggested by @Huy) or @project.stub(:msg) will stub the method.
Doing expect(@project).to receive(:msg) just allows you to make an assertion that the stub was called as many times as you expected.
If you don't make an assertion about it, or make your assertion general (e.g. @project.should_receive(:msg).at_least(:once)), then it doesn't matter if the method was called more than that.
You can find more info in the RSpec docs:
Method Stubs
Expectations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With