[Rspec-users] Fwd: Fwd: overriding mock expectations

David Chelimsky dchelimsky at gmail.com
Tue Oct 24 05:34:27 EDT 2006


again, intended for the list - hitting reply on these goes to the
individual, not the list - i need to fix that.

---------- Forwarded message ----------
From: David Chelimsky <dchelimsky at gmail.com>
Date: Oct 24, 2006 4:31 AM
Subject: Re: [Rspec-users] Fwd: overriding mock expectations
To: Micah Martin <micah at 8thlight.com>


On 10/23/06, Micah Martin <micah at 8thlight.com> wrote:
> On Oct 23, 2006, at 6:52 PM, David Chelimsky wrote:
> > In 0.7 (currently in trunk - to be released within a couple of weeks -
> > maybe even this week), you can do something close:
> >
> > setup do
> >   mock = mock("blah")
> >   mock.stub!(:msg).and_return(value)
> > end
> >
> > specify "something" do
> >   mock.should_receive(:msg).and_return(other_value)
> > end
> >
> > Would that solve your problem?
>
> Off the bat, it looks like that'd do.  It seems like should_receive
> (...).any_number_of_times is virtually the same as stubbing.  Is that
> correct?

Yes, with one additional bit. Stub messages and mock expectations are
stored separately. This allows the framework to first look for a mock
expectation and then look for a stub if it can't find a mock
expectation. Under the hood, they are instances of the subtypes of the
same class and the message expectation is actually
should_receive(:msg).any_number_of_times, as you suggest.

>
> Micah
>


More information about the Rspec-users mailing list