Skip to content

Commit

Permalink
stubbee -> stubba_object, mock_owner -> stubbee
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nitishr committed Jan 17, 2020
1 parent 3fc8e30 commit e28d7f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/mocha/any_instance_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ module Mocha
class AnyInstanceMethod < StubbedMethod
private

def mock_owner
stubbee.any_instance
def stubbee
stubba_object.any_instance
end

def method_body(method)
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
8 changes: 4 additions & 4 deletions lib/mocha/instance_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ module Mocha
class InstanceMethod < StubbedMethod
private

def mock_owner
stubbee
def stubbee
stubba_object
end

def method_body(method)
PRE_RUBY_V19 ? proc { |*args, &block| method.call(*args, &block) } : 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
14 changes: 7 additions & 7 deletions lib/mocha/stubbed_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/instance_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e28d7f7

Please sign in to comment.