[mocha-developer] Fwd: [Rails] Re: Re: Re: A mock which extends rather than replaces a clas

James Mead jamesmead44 at gmail.com
Wed Aug 16 08:02:24 EDT 2006

---------- Forwarded message ----------
From: Paul Butcher <paul at paulbutcher.com>
Date: 16-Aug-2006 12:55
Subject: [Rails] Re: Re: Re: A mock which extends rather than replaces a
To: rails at lists.rubyonrails.org

James Mead wrote:
> You could use Mocha to do the following...
> def test_send_unsolicited
>   conversation = mock()
>   conversation.stubs(:send_now!)
>   conversation.expects(:unlock!)
>   Conversation.stubs(:create_unsolicited).returns(conversation)
>   Conversation.send_unsolicited(nil, nil)
> end
> ... This test is stubbing out a lot
> of code, but it is focussed on verifying the unlock! call.

Which means that we can't use this approach in our particular case -
although the only thing that the example I gave you does is verify that
unlock! is called, the "real" test does quite a bit more :-)


> An alternative is...
> def test_send_unsolicited
>   Conversation.any_instance.expects(:unlock!)
>   Conversation.send_unsolicited(customers(:customer1), "Blah blah blah")
>   Conversation.any_instance.verify
> end
> This only replaces the unlock! method and verifies that it was called,
> so in this case you need to supply the parameters to send_unsolicited,
> so that create_unsolicited has something to work with. In this case,
> with the current version of Mocha, you need to manually call verify.

I think that this gives us exactly what we want :-)

Thank you!

> Make any sense?

Perfect sense. I'm installing Mocha now... :-)



Posted via http://www.ruby-forum.com/.
Rails mailing list
Rails at lists.rubyonrails.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060816/51e178b3/attachment.html 

More information about the mocha-developer mailing list