stub on inherited class method that is already stubbed in base class is not cleaned up properly #74

dchelimsky opened this Issue Apr 11, 2012 · 9 comments


None yet
2 participants
require 'rubygems'
require 'test/unit'
require 'mocha'

class Parent

class Child < Parent

class ParentAndChildTest < Test::Unit::TestCase
  def test_1

  def test_2


  1) Failure:
test_2(ParentAndChildTest) [example_test.rb:22]:
unexpected invocation:

My suspicion is that when the Child.stubs(:foo) after Parent.stubs(:foo), the stub implementation of is stored as the original foo method on Child. Then when the "original" method is restored, it's actually the stub implementation. I could be wrong :)

More info: this problem only happens when the subclass inherits the class method. If the subclass overrides the class method, then this problem does not appear.


floehopper commented Apr 13, 2012

I suspect this is related to #47.

@floehopper floehopper added a commit that referenced this issue Apr 13, 2012

@floehopper floehopper Merge pull request #75 from floehopper/alias-method-alternative
Store original method rather than using alias_method.

This should fix #41, #47, #74 and all tests should now pass on both Ruby 1.8.7 and 1.9.3.

floehopper commented Apr 13, 2012

I believe this issue should be resolved in the latest revision (4d3e2bb) of Mocha. Please close the issue if you are happy with the resolution.

dchelimsky closed this Apr 13, 2012

Seems to work well. Thanks!

FYI - do you have a rough ETA for a release? No worries if you don't, but if you do I'd like to know. Thx.


floehopper commented Apr 16, 2012

Hi David. I'm glad that works. Sorry not to get back to you sooner - I've been abroad on holiday with only intermittent internet connectivity. I'd like to get a bit more feedback on a couple of the other fixed issues and a bit more confidence that I haven't broken anything important, but I hope to release in the next couple of days. Cheers, James.

Thanks for the info, and please do enjoy the rest of your holiday!


floehopper commented Apr 21, 2012

Hi David. Just to let you know I released v0.11.0 a couple of days ago, but a Ruby 1.8.7 regression crept in, so I have yanked it and released v0.11.1 this morning. I hope that helps. Cheers, James.

floehopper was assigned Apr 21, 2012

Thanks for the update. Cheers, David.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment