[mocha-developer] with-arguments block is executed regardless of method?

James Mead jamesmead44 at gmail.com
Thu Feb 1 10:38:41 EST 2007

On 01/02/07, Jonathan del Strother <jon.delStrother at bestbefore.tv> wrote:
> I have a test case where I'm stubbing one method ('jobs'), and
> mocking another ('new_worker')
> MiddleMan.stubs(:jobs)
> MiddleMan.expects(:new_worker).with{|args| args[:class]
> ==:download_worker}
> MiddleMan.jobs()
> The above code results in an error ("The error occurred while
> evaluating nil.[]") - calling 'jobs' results in the with-arguments
> block for new_worker getting executed.
> Is this intended behaviour?

Thanks for your email.

Presumably it is the MiddleMan.jobs method that is expected to call the
MiddleMan.new_worker method? It would be helpful to have the code under test
as well as the test.

If yes, it seems strange that you would stub the MiddleMan.jobs method and
then call it. Stubbing it effectively temporarily replaces the
implementation of MiddleMan.jobs and so MiddleMan.new_worker will not be
called as expected.

All that being said, it looks like you've found a bug. It looks like Mocha
executes the with block even if the method name doesn't match. I'll try and
fix it asap.

BTW - you might want to subscribe to the list otherwise your emails won't
appear until I've got round to moderating them.


More information about the mocha-developer mailing list