[rspec-devel] mock frameworks
jamesmead44 at gmail.com
Mon May 14 14:09:07 EDT 2007
On 14/05/07, Brian Takita <brian.takita at gmail.com> wrote:
> I'm considering using Mocha + Mocha Shot.
Nice one! I like some of the ideas in this. Sorry not to have been
more responsive - things are as busy as ever at Reevoo.
> There are some things that are in Rspec's mocking framework that are missing
> in Mocha though.
> For example, in spec/mock, #and_return takes a block that gets executed and
> accepts the arguments passed to the method.
The Mocha returns() method can currently take an instance of a Proc
which you can use to define more complex behaviour. However it is true
that the parameters of the method are not passed to this Proc. But
this is intentional. Because you are completely and deterministically
in control of all the objects involved in the test, you should know
what sequence of return values you need to return from the mock. So
you can use something like...
m = mock()
m.stubs(:method).returns(1, 2, 3).then.raises(Exception).then.returns(5).
The fact that you need to know the parameters being passed in to the
stubbed method in order to work out what to return is probably a sign
that you are testing too much at once.
Anyway, if you need that degree of control, why not simply use
define_method. Or use a Rails-style "mock" (i.e. hard-coded fake
For similar reasons the ability of the returns() method to take an
instance of a Proc will probably be phased out soon.
Does that make sense?
More information about the rspec-devel