[mocha-developer] When to stub/when to mock (was Rails functional testing and Mocha)

David Chelimsky dchelimsky at gmail.com
Mon Mar 5 08:04:53 EST 2007

Hi James,

> From: James Mead <jamesmead44 at gmail.com>
> Date: Mar 5, 2007 5:15 AM
> Subject: Re: [mocha-developer] Rails functional testing and Mocha
> To: mocha-developer at rubyforge.org

> "I'd probably stub the call to find not expect it, because its a query not a command"

I have a different perspective on when to use stubs and when to use
mocks and I'm curious as to your thoughts about it.

I like to put stubs in setup, regardless of whether they are commands
or queries, and mock expectations in test methods (specify blocks in
rspec). This keeps the noise of what is necessary but uninteresting
(from the perspective of the tests) out of the way of the test
methods, which can focus entirely on the interesting bits.

The motivation is the same as Nat Pryce's - expecting only the
interesting bits will make tests less brittle - but the resulting
principle revolves on a different axis.

Thoughts on this?


More information about the mocha-developer mailing list