[rspec-users] [Rspec] Difference between stub and message expectation with any_number_of_times
David Chelimsky
dchelimsky at gmail.com
Tue Jul 13 19:04:12 EDT 2010
On Jul 13, 2010, at 11:29 AM, Benyi Wang wrote:
> I'm wondering what's the difference between stub and message expectation with any_number_of_times, for example:
>
> myMock = mock("mymock")
> myMock.stub!(:is_a?).with(MyClass).and_return(false)
>
> and
>
> myMock = mock("mymock")
> myMock.should_receive(:is_a?).with(MyClass).any_number_of_times.and_return(false)
>
> because is_a? may not be called at all, it just like a stub. Is my understanding correct?
Yes.
> Is there any guide how to use stub and message expectation?
any_number_of_times was introduced before we introduced stubs, way back, way back. I use stub() rather than should_receive + any_number_of_times.
HTH,
David
More information about the rspec-users
mailing list