I need to make sure a method is not called giving a specific set of conditions, and I'm looking for the opposite of the mocha expects.
Look at mocha's never
or rspec's should_not_receive
and should_receive(:selector).exactly(n).times
I'm not a mocha expert by any means, but I suspect what you need may be supplied by a never modifier for an expectation.
RSpec 3.6 now handles this with expect(...).not_to receive(...).
From the link:
RSpec.describe "A negative message expectation" do
it "passes if the message is never received" do
dbl = double("Some Collaborator").as_null_object
expect(dbl).not_to receive(:foo)
end
end
Mocha example from the documentation
object = mock()
object.expects(:expected_method).never
object.expected_method # => unexpected invocation
object = mock()
object.expects(:expected_method).never
# => verify succeeds
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