class Mocha::StubbedMethod
Constants
- PrependedModule
Attributes
Public Class Methods
Source
# File lib/mocha/stubbed_method.rb, line 10 def initialize(stubbee, method_name) @stubbee = stubbee @original_method = nil @original_visibility = nil @method_name = method_name.to_sym end
Public Instance Methods
Source
# File lib/mocha/stubbed_method.rb, line 43 def define_new_method self_in_scope = self method_name_in_scope = method_name stub_method_owner.send(:define_method, method_name) do |*args, &block| self_in_scope.mock.handle_method_call(method_name_in_scope, args, block) end stub_method_owner.send(:ruby2_keywords, method_name) retain_original_visibility(stub_method_owner) end
Source
# File lib/mocha/stubbed_method.rb, line 37 def hide_original_method return unless original_method_owner.__method_exists__?(method_name) store_original_method_visibility use_prepended_module_for_stub_method end
Source
# File lib/mocha/stubbed_method.rb, line 57 def matches?(other) return false unless other.class == self.class (stubbee.object_id == other.stubbee.object_id) && (method_name == other.method_name) end
Source
# File lib/mocha/stubbed_method.rb, line 53 def remove_new_method stub_method_owner.send(:remove_method, method_name) end
Source
# File lib/mocha/stubbed_method.rb, line 33 def reset_mocha mock_owner.reset_mocha end
Source
# File lib/mocha/stubbed_method.rb, line 17 def stub hide_original_method define_new_method end
Source
# File lib/mocha/stubbed_method.rb, line 22 def unstub remove_new_method mock.unstub(method_name.to_sym) return if mock.any_expectations? reset_mocha end
Private Instance Methods
Source
# File lib/mocha/stubbed_method.rb, line 70 def retain_original_visibility(method_owner) return unless @original_visibility Module.instance_method(@original_visibility).bind(method_owner).call(method_name) end
Source
# File lib/mocha/stubbed_method.rb, line 75 def store_original_method_visibility @original_visibility = original_method_owner.__method_visibility__(method_name) end
Source
# File lib/mocha/stubbed_method.rb, line 84 def stub_method_owner @stub_method_owner ||= original_method_owner end
Source
# File lib/mocha/stubbed_method.rb, line 79 def use_prepended_module_for_stub_method @stub_method_owner = PrependedModule.new original_method_owner.__send__ :prepend, @stub_method_owner end