module RSpec::Mocks::PartialClassDoubleProxyMethods
def original_method_handle_for(message)
That's what this method (together with `original_unbound_method_handle_from_ancestor_for`)
run with the proper `self`.
from _before_ `A` was stubbed, and we need to rebind it to `B` so that it will
To do it properly, we need to find the original definition of `new` from `A`
hierarchy.
of the method on `A` since singleton methods on classes are in the lookup
`B.method(:new)` will return a method that will execute the stubbed version
using `B.method(:new)` before our redefinition is defined on `B`, because
When getting the original definition for `B.new`, we cannot rely purely on
expect(B).to receive(:new).and_call_original
allow(A).to receive(:new)
class B < A; end
class A; end
Consider this situation:
def original_method_handle_for(message) unbound_method = superclass_proxy && superclass_proxy.original_unbound_method_handle_from_ancestor_for(message.to_sym) return super unless unbound_method unbound_method.bind(object) # :nocov: rescue TypeError if RUBY_VERSION == '1.8.7' # In MRI 1.8.7, a singleton method on a class cannot be rebound to its subclass if unbound_method && unbound_method.owner.ancestors.first != unbound_method.owner # This is a singleton method; we can't do anything with it # But we can work around this using a different implementation double = method_double_from_ancestor_for(message) return object.method(double.method_stasher.stashed_method_name) end end raise # :nocov: end