[mocha-developer] problem with using any_instance

James Mead jamesmead44 at gmail.com
Fri Mar 30 13:50:58 EDT 2007


I've just tried to recreate your problem...

require 'test/unit'
require 'rubygems'
require 'mocha'

class AnyInstanceTest < Test::Unit::TestCase

  class Klass
    def method_name
      "original"
    end
  end

  def test_a
    Klass.any_instance.stubs(:method_name).returns("something")
    assert_equal "something", Klass.new.method_name
  end

  def test_b
    assert_equal "original", Klass.new.method_name
  end

end

...but both tests pass. So I don't understand why you are having a problem.

Please send us all the code for the simplest self-contained test case which
illustrates your problem?

What version of Mocha are you using? And are you using it as a gem or as
Rails plugin?

-- 
James.
http://blog.floehopper.org


More information about the mocha-developer mailing list