Jonathan del Strother
2007-Feb-01 14:11 UTC
[mocha-developer] with-arguments block is executed regardless of method?
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? Jon
James Mead
2007-Feb-01 15:38 UTC
[mocha-developer] with-arguments block is executed regardless of method?
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. -- James. http://blog.floehopper.org
James Mead
2007-Feb-01 15:51 UTC
[mocha-developer] with-arguments block is executed regardless of method?
On 01/02/07, James Mead <jamesmead44 at gmail.com> wrote:> > 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. >Should be fixed in revision 98 of trunk. -- James. http://blog.floehopper.org
Jonathan del Strother
2007-Feb-01 18:02 UTC
[mocha-developer] with-arguments block is executed regardless of method?
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.