[mocha-developer] Mocha Mock's hanging on after test run?

Kevin Clark kevin.clark at gmail.com
Wed Jan 17 00:28:26 EST 2007


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


More information about the mocha-developer mailing list