[mocha-developer] Using any_instance with Rails to make sure the right thing is saved?

James Mead jamesmead44 at gmail.com
Thu Feb 8 06:11:16 EST 2007

On 07/02/07, James Moore <jamesthepiper at gmail.com> wrote:
> Is there a standard way to get information from the 'with' bit to the
> 'return' bit?

No. Intentionally not.

It'd be useful to be able to build the return object based on
> information from the original call to 'new'.  I did it by stashing away
> the
> values in the 'with' block to be used later on in the Proc used by
> return():

If you really want to do that, you'd be better off with a traditional Rails
"mock" object i.e. an alternative class definition in the "test/mocks"
directory. These are what Martin Fowler terms Fake Objects (see

But that seems goofy.  Is there a) either a better way to pass around the
> values from #with to #returns, or b) am I just misusing mocks, and
> I should always specify all the values?

I think you get much clearer tests if you explicitly specify the return
values in each scenario.

More information about the mocha-developer mailing list