I am stubbing a method like this in the setup of one of my tests
def setup
super
#blah, blah
GoogleIdentity.stubs(:new).with(google_identity).returns(google_account)
end
The problem is that not every test will invoke the method and return the object.
In the methods that do not invoke the method, I get this error:
allowed any number of times, not yet invoked: GoogleIdentity.new()
It seems like mocha is complaining because the method was not invoked.
How can I specify a stub that does not expect it to be calle?
I think that the implementation of mocha is broken. A method called stubs should not care about being called or not. That should be the responsibility of a mocks method.
This behavior is one of the things I don't use mocha anymore.
From what I remember when fixing this issue, I used one of the expectations to handle this scenario like at_most(1).
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