[rspec-users] Surprising mock behavior

Zach Dennis zach.dennis at gmail.com
Fri Oct 17 15:54:36 EDT 2008

On Fri, Oct 17, 2008 at 3:37 PM, Stephen Eley <sfeley at gmail.com> wrote:
> On Fri, Oct 17, 2008 at 2:55 PM, Mark Thomson <mark.thomson at ieee.org> wrote:
>> and then check that the expected messages are being received -
>> file.should_receive(:puts).with("a string").once
>> file.should_receive(:puts).with("another string").once
>> Here's what I'm puzzled about. If I don't include the expectation for the
>> first string in the spec, the spec will fail the expectation for the second
>> string. It seems as if "should_receive" is queuing up the messages that come
>> into the file object and when it tests an expectation it just looks at the
>> next one in line. If it doesn't match then the expectation will fail.
> That sounds right to me.  You declared 'file' as a mock.  Mocks are
> bratty little children that treat it as an error and throw a tantrum
> if you don't give them everything they expect, no more nor less.

Are you a proud parent? :)

Zach Dennis

More information about the rspec-users mailing list