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

Jonathan del Strother jon.delStrother at bestbefore.tv
Thu Feb 1 13:02:25 EST 2007


On 01/02/07, James Mead <jamesmead44 at gmail.com> wrote:
>
> 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.

Yeah, sorry.  MiddleMan.jobs was purely there to illustrate the  
problem - it's called by other unrelated actions within the test case.


On 01/02/07, James Mead <jamesmead44 at gmail.com> wrote:
> Should be fixed in revision 98 of trunk.

Thanks, I'll try it out.


More information about the mocha-developer mailing list