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.
Asked
Active
Viewed 1.1k times
4 Answers
28
Look at mocha's never
or rspec's should_not_receive
and should_receive(:selector).exactly(n).times

p.matsinopoulos
- 7,655
- 6
- 44
- 92

Jonah
- 17,918
- 1
- 43
- 70
-
2Mocha link is outdated. [New documentation on never](http://gofreerange.com/mocha/docs/Mocha/Expectation.html#never-instance_method) – Seth Bro Oct 01 '14 at 03:19
3
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

RamRovi
- 986
- 9
- 13
2
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

Shawn I
- 53
- 7