Kevin Clark
2007-Jan-17 05:28 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
Hi guys, I''m running mocha (0.3.2) against Rails core and just found an issue where the mock doesn''t go away after the test is run. For example: def test_reset_bang_doesn_reinstall_named_routes ActionController::Routing::Routes.named_routes.expects(:install).never @session.reset! end def test_zzz puts ActionController::Routing::Routes.named_routes.inspect assert !ActionController::Routing::Routes.named_routes end The print when test_zzz is run gives this: #<ActionController::Routing::RouteSet::NamedRouteCollection:0x14e0da8 @mocha=#<Mocha::Mock:0x2333504 @__mock_name=nil, @expectations=[#<Mocha::Expectation:0x2333158 @count=0, @parameter_block=nil, @backtrace=["test/controller/integration_test.rb:146:in `test_reset_bang_doesn_reinstall_named_routes''", "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `__send__''", "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `run''", "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite''", "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in `start_mediator''", "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in `start''", "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run''", "/usr/local/lib/ruby/1.8/test/unit.rb:278", "test/controller/integration_test.rb:6"], @return_value=nil, @parameters=** any **, @invoked=4, @method_name=:install>], @stub_everything=false>, @module=#<Module:0x14e0d44>, @helpers=[], @routes={}> This is a big deal because this causes tests to fail in other places in the framework. Ideas? -- Kevin Clark http://glu.ttono.us
James Mead
2007-Jan-17 11:26 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote:> > Hi guys, > I''m running mocha (0.3.2) against Rails core and just found an issue > where the mock doesn''t go away after the test is run. > > For example: > > def test_reset_bang_doesn_reinstall_named_routes > ActionController::Routing::Routes.named_routes.expects(:install).never > @session.reset! > end > > def test_zzz > puts ActionController::Routing::Routes.named_routes.inspect > assert !ActionController::Routing::Routes.named_routes > end > > The print when test_zzz is run gives this: > > #<ActionController::Routing::RouteSet::NamedRouteCollection:0x14e0da8 > @mocha=#<Mocha::Mock:0x2333504 @__mock_name=nil, > @expectations=[#<Mocha::Expectation:0x2333158 @count=0, > @parameter_block=nil, > @backtrace=["test/controller/integration_test.rb:146:in > `test_reset_bang_doesn_reinstall_named_routes''", > "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `__send__''", > "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `run''", > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", > "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in > `run_suite''", > "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in > `start_mediator''", > "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in > `start''", > "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in > `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in > `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run''", > "/usr/local/lib/ruby/1.8/test/unit.rb:278", > "test/controller/integration_test.rb:6"], @return_value=nil, > @parameters=** any **, @invoked=4, @method_name=:install>], > @stub_everything=false>, @module=#<Module:0x14e0d44>, @helpers=[], > @routes={}> > > > This is a big deal because this causes tests to fail in other places > in the framework. > > Ideas? >Hi Kevin, Sorry not to respond sooner - I''ve been away on holiday. I''ve managed to reproduce the problem locally. I haven''t had a chance to investigate it thoroughly, but it looks like you could fix it by patching the gem as follows... Replace the comment on line #13 of instance_method.rb as follows... def unstub # intentionally empty end becomes... def unstub stubbee.reset_mocha end I''m not sure how this bug crept in, but the HEAD version of Mocha does not seem to have the same bug. We''re really close to releasing a new version (0.4) of the gem, but if this is causing you serious problems I will release a patched 0.3.3 version. (Note that the patch above will break a couple of unit tests). Let me know. -- James. http://blog.floehopper.org
Kevin Clark
2007-Jan-17 18:44 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
Hi James, Since this is going into rails core, the fix would need to make tests pass for _everyone_ doing dev, so just patching the local machine won''t work. I''ll wait on 0.4 (hopefully soon). Thanks for all the work. You guys are great. Kev On 1/17/07, James Mead <jamesmead44 at gmail.com> wrote:> On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote: > > > > Hi guys, > > I''m running mocha (0.3.2) against Rails core and just found an issue > > where the mock doesn''t go away after the test is run. > > > > For example: > > > > def test_reset_bang_doesn_reinstall_named_routes > > ActionController::Routing::Routes.named_routes.expects(:install).never > > @session.reset! > > end > > > > def test_zzz > > puts ActionController::Routing::Routes.named_routes.inspect > > assert !ActionController::Routing::Routes.named_routes > > end > > > > The print when test_zzz is run gives this: > > > > #<ActionController::Routing::RouteSet::NamedRouteCollection:0x14e0da8 > > @mocha=#<Mocha::Mock:0x2333504 @__mock_name=nil, > > @expectations=[#<Mocha::Expectation:0x2333158 @count=0, > > @parameter_block=nil, > > @backtrace=["test/controller/integration_test.rb:146:in > > `test_reset_bang_doesn_reinstall_named_routes''", > > "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `__send__''", > > "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `run''", > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", > > "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in > > `run_suite''", > > "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in > > `start_mediator''", > > "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in > > `start''", > > "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in > > `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in > > `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run''", > > "/usr/local/lib/ruby/1.8/test/unit.rb:278", > > "test/controller/integration_test.rb:6"], @return_value=nil, > > @parameters=** any **, @invoked=4, @method_name=:install>], > > @stub_everything=false>, @module=#<Module:0x14e0d44>, @helpers=[], > > @routes={}> > > > > > > This is a big deal because this causes tests to fail in other places > > in the framework. > > > > Ideas? > > > > Hi Kevin, > > Sorry not to respond sooner - I''ve been away on holiday. > > I''ve managed to reproduce the problem locally. > > I haven''t had a chance to investigate it thoroughly, but it looks like you > could fix it by patching the gem as follows... > > Replace the comment on line #13 of instance_method.rb as follows... > > def unstub > # intentionally empty > end > > becomes... > > def unstub > stubbee.reset_mocha > end > > I''m not sure how this bug crept in, but the HEAD version of Mocha does not > seem to have the same bug. > > We''re really close to releasing a new version (0.4) of the gem, but if this > is causing you serious problems I will release a patched 0.3.3 version. > > (Note that the patch above will break a couple of unit tests). > > Let me know. > > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >-- Kevin Clark http://glu.ttono.us
Kevin Clark
2007-Jan-17 19:21 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
Oh, or re-reading this, if you''d like to push a bugfix it would make my life easy :) On 1/17/07, Kevin Clark <kevin.clark at gmail.com> wrote:> Hi James, > Since this is going into rails core, the fix would need to make tests > pass for _everyone_ doing dev, so just patching the local machine > won''t work. > > I''ll wait on 0.4 (hopefully soon). Thanks for all the work. You guys are great. > > Kev > > On 1/17/07, James Mead <jamesmead44 at gmail.com> wrote: > > On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote: > > > > > > Hi guys, > > > I''m running mocha (0.3.2) against Rails core and just found an issue > > > where the mock doesn''t go away after the test is run. > > > > > > For example: > > > > > > def test_reset_bang_doesn_reinstall_named_routes > > > ActionController::Routing::Routes.named_routes.expects(:install).never > > > @session.reset! > > > end > > > > > > def test_zzz > > > puts ActionController::Routing::Routes.named_routes.inspect > > > assert !ActionController::Routing::Routes.named_routes > > > end > > > > > > The print when test_zzz is run gives this: > > > > > > #<ActionController::Routing::RouteSet::NamedRouteCollection:0x14e0da8 > > > @mocha=#<Mocha::Mock:0x2333504 @__mock_name=nil, > > > @expectations=[#<Mocha::Expectation:0x2333158 @count=0, > > > @parameter_block=nil, > > > @backtrace=["test/controller/integration_test.rb:146:in > > > `test_reset_bang_doesn_reinstall_named_routes''", > > > "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `__send__''", > > > "/usr/local/lib/ruby/1.8/test/unit/testcase.rb:72:in `run''", > > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", > > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", > > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", > > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''", > > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''", > > > "/usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''", > > > "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in > > > `run_suite''", > > > "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in > > > `start_mediator''", > > > "/usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in > > > `start''", > > > "/usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in > > > `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in > > > `run''", "/usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run''", > > > "/usr/local/lib/ruby/1.8/test/unit.rb:278", > > > "test/controller/integration_test.rb:6"], @return_value=nil, > > > @parameters=** any **, @invoked=4, @method_name=:install>], > > > @stub_everything=false>, @module=#<Module:0x14e0d44>, @helpers=[], > > > @routes={}> > > > > > > > > > This is a big deal because this causes tests to fail in other places > > > in the framework. > > > > > > Ideas? > > > > > > > Hi Kevin, > > > > Sorry not to respond sooner - I''ve been away on holiday. > > > > I''ve managed to reproduce the problem locally. > > > > I haven''t had a chance to investigate it thoroughly, but it looks like you > > could fix it by patching the gem as follows... > > > > Replace the comment on line #13 of instance_method.rb as follows... > > > > def unstub > > # intentionally empty > > end > > > > becomes... > > > > def unstub > > stubbee.reset_mocha > > end > > > > I''m not sure how this bug crept in, but the HEAD version of Mocha does not > > seem to have the same bug. > > > > We''re really close to releasing a new version (0.4) of the gem, but if this > > is causing you serious problems I will release a patched 0.3.3 version. > > > > (Note that the patch above will break a couple of unit tests). > > > > Let me know. > > > > -- > > James. > > http://blog.floehopper.org > > _______________________________________________ > > mocha-developer mailing list > > mocha-developer at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mocha-developer > > > > > -- > Kevin Clark > http://glu.ttono.us >-- Kevin Clark http://glu.ttono.us
James Mead
2007-Jan-17 23:24 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote:> > Oh, or re-reading this, if you''d like to push a bugfix it would make > my life easy :)Hi Kevin, I''ve just had another quick look at this and I think it requires more work than I first thought. My suggested fix only clears the expectations - it does not return the method to its original implementation. The assumption made by Mocha is that any concrete instances on which expectations are set will not be re-used between tests. In the example you give, state (in the form of the Routes constant which references an instance of RouteSet) is being preserved between tests - hence Mocha''s assumption is broken. It shouldn''t be too hard to ensure that Mocha deals with this scenario, but I need to get some sleep now. I''ll take another look in the morning. I assume that you''re retro-fitting tests to code that you don''t want to change. Otherwise I''d suggest re-writing the code to be more easily testable and avoid retaining state between tests. -- James. http://blog.floehopper.org
Kevin Clark
2007-Jan-17 23:47 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
Hi James, Yes, I''d much rather rewrite the tests and code, but as it''s the rails routing code and it''s lacking in the test department... ;) Thanks for the hard work. I really appreciate it. Let me know if there''s some way I can help. Kev On 1/17/07, James Mead <jamesmead44 at gmail.com> wrote:> On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote: > > > > Oh, or re-reading this, if you''d like to push a bugfix it would make > > my life easy :) > > > > Hi Kevin, > > I''ve just had another quick look at this and I think it requires more work > than I first thought. My suggested fix only clears the expectations - it > does not return the method to its original implementation. > > The assumption made by Mocha is that any concrete instances on which > expectations are set will not be re-used between tests. In the example you > give, state (in the form of the Routes constant which references an instance > of RouteSet) is being preserved between tests - hence Mocha''s assumption is > broken. It shouldn''t be too hard to ensure that Mocha deals with this > scenario, but I need to get some sleep now. I''ll take another look in the > morning. > > I assume that you''re retro-fitting tests to code that you don''t want to > change. Otherwise I''d suggest re-writing the code to be more easily testable > and avoid retaining state between tests. > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >-- Kevin Clark http://glu.ttono.us
James Mead
2007-Jan-18 10:12 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote:> > Hi James, > Yes, I''d much rather rewrite the tests and code, but as it''s the rails > routing code and it''s lacking in the test department... ;) > > Thanks for the hard work. I really appreciate it. Let me know if > there''s some way I can help. > > Kev >No problem. I think I''ve fixed it and created a new gem, but Rubyforge seems to be down so I can''t publish it there at the moment. In the meantime, you should be able to download it from here ( http://download.cl1p.net/mocha-0.3.3.gem/). Please let me know if you run into any problems. -- James. http://blog.floehopper.org
James Mead
2007-Jan-18 16:00 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
On 18/01/07, James Mead <jamesmead44 at gmail.com> wrote:> > No problem. I think I''ve fixed it and created a new gem, but Rubyforge > seems to be down so I can''t publish it there at the moment. >0.3.3 gem now on rubyforge. -- James. http://blog.floehopper.org
Kevin Clark
2007-Jan-18 22:38 UTC
[mocha-developer] Mocha Mock''s hanging on after test run?
Bug seems to be fixed, and ticket is ready to go. Thanks a ton. Kev On 1/18/07, James Mead <jamesmead44 at gmail.com> wrote:> On 18/01/07, James Mead <jamesmead44 at gmail.com> wrote: > > > > No problem. I think I''ve fixed it and created a new gem, but Rubyforge > > seems to be down so I can''t publish it there at the moment. > > > > 0.3.3 gem now on rubyforge. > > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >-- Kevin Clark http://glu.ttono.us