Permalink
Browse files

Alias the original method first to avoid warnings

  • Loading branch information...
1 parent b2bb1aa commit 049a10d4051a48136199fcdfd77bf35df9e9ad11 @rafaelfranca rafaelfranca committed Jan 29, 2014
Showing with 7 additions and 2 deletions.
  1. +7 −2 activesupport/lib/active_support/testing/time_helpers.rb
@@ -14,8 +14,11 @@ def stub_object(object, method_name, return_value)
unstub_object(stub)
end
- @stubs[key] = Stub.new(object, method_name, object.method(method_name))
+ new_name = "__simple_stub__#{method_name}"
+ @stubs[key] = Stub.new(object, method_name, new_name)
+
+ object.singleton_class.send :alias_method, new_name, method_name
object.define_singleton_method(method_name) { return_value }
end
@@ -27,7 +30,9 @@ def unstub_all!
end
def unstub_object(stub)
- stub.object.define_singleton_method(stub.method_name, stub.original_method)
+ stub.object.singleton_class.send :undef_method, stub.method_name
+ stub.object.singleton_class.send :alias_method, stub.method_name, stub.original_method
+ stub.object.singleton_class.send :undef_method, stub.original_method
end
end

0 comments on commit 049a10d

Please sign in to comment.