From e28d7f71c37dab3338102f2401267eb7e17264ac Mon Sep 17 00:00:00 2001 From: Nitish Rathi Date: Fri, 17 Jan 2020 03:53:29 +0000 Subject: [PATCH] stubbee -> stubba_object, mock_owner -> stubbee stubbee is the thing that's stubbed - more specifically, the object on which .stubs or .mocks is called. Therefore, it's also the object that holds a reference to mocha. That's why it was called mock_owner earlier. stubba_object is the object through which we get hold of the stubba_class on which stubbed methods reside. In case of AnyInstance, that class is the stubba_object itself, while in case of Instance, it's the singleton class of the stubba_object. --- lib/mocha/any_instance_method.rb | 8 ++++---- lib/mocha/instance_method.rb | 8 ++++---- lib/mocha/stubbed_method.rb | 14 +++++++------- test/unit/instance_method_test.rb | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/mocha/any_instance_method.rb b/lib/mocha/any_instance_method.rb index 8b128ea99..1445d224f 100644 --- a/lib/mocha/any_instance_method.rb +++ b/lib/mocha/any_instance_method.rb @@ -5,8 +5,8 @@ module Mocha class AnyInstanceMethod < StubbedMethod private - def mock_owner - stubbee.any_instance + def stubbee + stubba_object.any_instance end def method_body(method) @@ -14,11 +14,11 @@ def method_body(method) end def stubbee_method(method_name) - stubbee.instance_method(method_name) + stubba_object.instance_method(method_name) end def original_method_owner - stubbee + stubba_object end end end diff --git a/lib/mocha/instance_method.rb b/lib/mocha/instance_method.rb index 86909ebe1..0e5cf30b8 100644 --- a/lib/mocha/instance_method.rb +++ b/lib/mocha/instance_method.rb @@ -4,8 +4,8 @@ module Mocha class InstanceMethod < StubbedMethod private - def mock_owner - stubbee + def stubbee + stubba_object end def method_body(method) @@ -13,11 +13,11 @@ def method_body(method) end def stubbee_method(method_name) - stubbee._method(method_name) + stubba_object._method(method_name) end def original_method_owner - stubbee.singleton_class + stubba_object.singleton_class end end end diff --git a/lib/mocha/stubbed_method.rb b/lib/mocha/stubbed_method.rb index 48a1e17b1..f73302e5a 100644 --- a/lib/mocha/stubbed_method.rb +++ b/lib/mocha/stubbed_method.rb @@ -5,10 +5,10 @@ module Mocha class StubbedMethod PrependedModule = Class.new(Module) - attr_reader :stubbee, :method_name + attr_reader :stubba_object, :method_name - def initialize(stubbee, method_name) - @stubbee = stubbee + def initialize(stubba_object, method_name) + @stubba_object = stubba_object @original_method = nil @original_visibility = nil @method_name = PRE_RUBY_V19 ? method_name.to_s : method_name.to_sym @@ -28,11 +28,11 @@ def unstub end def mock - mock_owner.mocha + stubbee.mocha end def reset_mocha - mock_owner.reset_mocha + stubbee.reset_mocha end def hide_original_method @@ -81,13 +81,13 @@ def restore_original_method def matches?(other) return false unless other.class == self.class - (stubbee.object_id == other.stubbee.object_id) && (method_name == other.method_name) + (stubba_object.object_id == other.stubba_object.object_id) && (method_name == other.method_name) end alias_method :==, :eql? def to_s - "#{stubbee}.#{method_name}" + "#{stubba_object}.#{method_name}" end private diff --git a/test/unit/instance_method_test.rb b/test/unit/instance_method_test.rb index f903c09e0..7e5c24cf7 100644 --- a/test/unit/instance_method_test.rb +++ b/test/unit/instance_method_test.rb @@ -219,7 +219,7 @@ def reset_mocha self.reset_mocha_called = true end end.new - replace_instance_method(method, :stubbee) { stubbee } + replace_instance_method(method, :stubba_object) { stubbee } method.unstub