[rspec-users] should_receive.again

Jonathan Linowes jonathan at parkerhill.com
Sun Jun 3 23:47:59 EDT 2007


The issue was the number of calls. I really only want to count the  
number of calls by the specific action.
But there's a before filter which calls the same method.
I couldn't stub out the before filter itself because it sets an  
instance variable used by the action.
Does that make sense?
So my example has to know more about the implementation than I would  
like.

On Jun 3, 2007, at 10:19 PM, nicholas a. evans wrote:

> On 6/3/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
>> On 6/3/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:
>>> This would be helpful because I have a setup method that sets up the
>>> should_receive once, and then some specific actions may use that
>>> method one or more additional times.
>>
>> @thing.should_receive(:method).exactly(3).times.and_return(@value)
>> http://rspec.rubyforge.org/rdoc/classes/Spec/Mocks.html
>
> You might also consider simply stubbing the method in your setup, and
> only specifying a number of times called in specific examples.
> Whenever reasonable, I try to follow the advice given by David
> Chelimsky and aim for no mock expectations in the setup and only one
> per example: http://blog.davidchelimsky.net/articles/2006/11/09/ 
> tutorial-rspec-stubs-and-mocks
>
> Also, you might want to think about whether or not you really should
> be locking down your specification to exactly three (or however many)
> calls.  Without knowing your details I can't say for certain if this
> applies to you, but often the exact number of calls is an
> implementation detail that your spec doesn't need to worry about.  If
> that's the case, I might loosen up the mock expectation a little bit
> by simply saying
> @thing.should_receive(:method).at_least(:once).and_return(@value)
>
> -- 
> Nick
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list