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.
Is there a "not_expects" for mocha/rspec?
Asked Answered
Look at mocha's never
or rspec's should_not_receive
and should_receive(:selector).exactly(n).times
Mocha link is outdated. New documentation on never –
Behalf
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.
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
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
© 2022 - 2024 — McMap. All rights reserved.