# File lib/rspec/mocks/method_double.rb, line 44 def original_method if @method_stasher.method_is_stashed? # Example: a singleton method defined on @object ::RSpec::Mocks.method_handle_for(@object, @method_stasher.stashed_method_name) elsif meth = original_unrecorded_any_instance_method # Example: a method that has been mocked through # klass.any_instance.should_receive(:msg).and_call_original # any_instance.should_receive(:msg) causes the method to be # replaced with a proxy method, and then `and_call_original` # is recorded and played back on the object instance. We need # special handling here to get a handle on the original method # object rather than the proxy method. meth else begin # Example: an instance method defined on one of @object's ancestors. original_method_from_ancestor(object_singleton_class.ancestors) rescue NameError raise unless @object.respond_to?(:superclass) # Example: a singleton method defined on @object's superclass. # # Note: we have to give precedence to instance methods # defined on @object's class, because in a case like: # # `klass.should_receive(:new).and_call_original` # # ...we want `Class#new` bound to `klass` (which will return # an instance of `klass`), not `klass.superclass.new` (which # would return an instance of `klass.superclass`). original_method_from_superclass end end rescue NameError # We have no way of knowing if the object's method_missing # will handle this message or not...but we can at least try. # If it's not handled, a `NoMethodError` will be raised, just # like normally. Proc.new do |*args, &block| @object.__send__(:method_missing, @method_name, *args, &block) end end