[Rspec-users] overriding mock expectations

Craig Demyanovich demmer12 at fastmail.us
Mon Oct 23 22:42:53 EDT 2006

On Oct 23, 2006, at 6:34 PM, Micah Martin wrote:

> There is one annoyance I'm encountering with the  Mock API in  
> rSpec.  Overall it works well, as far as dynamic mocks go ;)... but  
> there's this one thing... It doesn't allow overriding of expectations.
> example:
> m = mock("blah")
> m.should_receive(:one).any_number_of_times().and_return(1)
> m.should_receive(:one).and_return(1)
> The second call to should_receive is ignored.  I believe it would  
> be most convenient if the second call to should_receive would  
> override the first.
> Why?
> What I would like to do is define all the should_receives once in  
> the setup using any_number_of_times.  This establishes a default  
> context.  Then in each spec I'd like to override a specific  
> should_receive relevant to the spec.
> Without being able to override, I am force to define all the  
> should_receives for each spec..... duplication.
> Is there another solution I'm missing?

I'm wondering if you should just move the specs that you want to  
override to another context, since the setup is different.


More information about the Rspec-users mailing list