Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Alias `Object#method` to `Object#_method`

This will fix the problem when using Mocha to stub an object that reimplement `#method` method.
  • Loading branch information...
commit 8b5053c42cc6cbb31f2e406b615ce0cf1018a836 1 parent 5f40c6a
@sikachu authored
View
2  lib/mocha/class_method.rb
@@ -36,7 +36,7 @@ def reset_mocha
def hide_original_method
if method_exists?(method)
begin
- @original_method = stubbee.method(method)
+ @original_method = stubbee._method(method)
if @original_method && @original_method.owner == stubbee.__metaclass__
@original_visibility = :public
if stubbee.__metaclass__.protected_instance_methods.include?(method)
View
3  lib/mocha/object.rb
@@ -13,6 +13,9 @@ module Mocha
module ObjectMethods
# @private
+ alias_method :_method, :method
+
+ # @private
def mocha
@mocha ||= Mocha::Mockery.instance.mock_impersonating(self)
end
View
7 test/unit/class_method_test.rb
@@ -24,6 +24,13 @@ def test_should_not_raise_error_hiding_method_that_isnt_defined
assert_nothing_raised { method.hide_original_method }
end
+ def test_should_not_raise_error_hiding_method_in_class_that_implement_method_method
+ klass = Class.new { def self.method; end }
+ method = ClassMethod.new(klass, :method)
+
+ assert_nothing_raised { method.hide_original_method }
+ end
+
def test_should_define_a_new_method_which_should_call_mocha_method_missing
klass = Class.new { def self.method_x; end }
mocha = build_mock
View
5 test/unit/object_test.rb
@@ -84,4 +84,9 @@ def test_nobody_expects_the_spanish_inquisition
assert_raise(Mocha::ExpectationError) { object.expects(:the_spanish_inquisition) }
end
+ def test_should_alias_object_method
+ klass = Class.new { def self.method_x; end }
+ assert_equal klass._method(:method_x), klass.method(:method_x)
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.