[rspec-users] should_receive.again

nicholas a. evans nick at ekenosen.net
Sun Jun 3 22:19:54 EDT 2007

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


More information about the rspec-users mailing list