Skip to content

Commit

Permalink
Refactor: extract & reuse stubbed_method
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr committed Dec 4, 2019
1 parent 7494b2d commit 5f83af5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/mocha/object_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def stubba_class
singleton_class
end

# @private
def stubbed_method(method_name)
stubba_method.new(stubba_object, method_name)
end

# Adds an expectation that the specified method must be called exactly once with any parameters.
#
# The original implementation of the method is replaced during the test and then restored at the end of the test. The temporary replacement method has the same visibility as the original method.
Expand Down Expand Up @@ -133,8 +138,7 @@ def stubs(stubbed_methods_vs_return_values)
def unstub(*method_names)
mockery = Mocha::Mockery.instance
method_names.each do |method_name|
method = stubba_method.new(stubba_object, method_name)
mockery.stubba.unstub(method)
mockery.stubba.unstub(stubbed_method(method_name))
end
end

Expand All @@ -158,7 +162,7 @@ def anticipates(methods_vs_return_values)

def stub_method(mockery, method_name)
mockery.on_stubbing(self, method_name)
mockery.stubba.stub(stubba_method.new(stubba_object, method_name))
mockery.stubba.stub(stubbed_method(method_name))
end
end
end

0 comments on commit 5f83af5

Please sign in to comment.