RSpec: specifying multiple calls to a method with different argument each time
Similar to this question. The recommended solution is to call as_null_object
to avoid the confusion of messages. So:
describe Object do
it "fails, as expected, (using null object)" do
foo = mock('foo').as_null_object
foo.should_receive(:bar).once.ordered.with(1)
foo.should_receive(:bar).once.ordered.with(2)
foo.bar(1)
foo.bar(999) # => Mock "foo" expected :bar with (2) once, but received it 0 times
end
end
The output is not the same as your second case (i.e. "expected 2 but got 999"), but it does show that the expectation was not met.