[mocha-developer] problem with using any_instance

Yi Wen hayafirst at gmail.com
Fri Mar 30 12:40:24 EDT 2007


Hey all,

I have a question with using mocha in my tests.

In the same test file, I have two tests,

<code>
def test_a
  klass.any_instance.stubs(:method_name).returns("something")
  klass.new.method_name
  ...
end

def test_b
 ...
   klass.new.method_name
 ...
end
</code>

where klass is some class

when the tests run,  test _a passes, but test_b had an error like this:

test_b
NoMethodError: undefined method `method_name' for #<klass:0xb6fb1934>

I put a
<code>
  puts 'unstub called'
</code>
in unstub of any_instance_method.rb and it got called wen running test_a

Any idea what the problem it could be?

Thanks,

Yi


More information about the mocha-developer mailing list