Skip to content

Commit

Permalink
Refactor: inline anticipates into expects
Browse files Browse the repository at this point in the history
This reduces the surface area of the internal API exposed to users as
suggested in #467
  • Loading branch information
nitishr committed Feb 21, 2020
1 parent 55fc710 commit caea3a3
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/mocha/object_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ def stubba_method_for(method_name)
#
# @see Mock#expects
def expects(expected_methods_vs_return_values)
anticipates(expected_methods_vs_return_values)
if frozen?
raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
end
mocha.anticipates(expected_methods_vs_return_values, caller) do |method_name|
Mockery.instance.stub_method(self, method_name)
end
end

# Adds an expectation that the specified method may be called any number of times with any parameters.
Expand Down Expand Up @@ -105,7 +110,7 @@ def expects(expected_methods_vs_return_values)
#
# @see Mock#stubs
def stubs(stubbed_methods_vs_return_values)
anticipates(stubbed_methods_vs_return_values).at_least(0)
expects(stubbed_methods_vs_return_values).at_least(0)
end

# Removes the specified stubbed methods (added by calls to {#expects} or {#stubs}) and all expectations associated with them.
Expand Down Expand Up @@ -137,16 +142,5 @@ def unstub(*method_names)
mockery.stubba.unstub(stubba_method_for(method_name))
end
end

private

def anticipates(expected_methods_vs_return_values)
if frozen?
raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
end
mocha.anticipates(expected_methods_vs_return_values, caller) do |method_name|
Mockery.instance.stub_method(self, method_name)
end
end
end
end

0 comments on commit caea3a3

Please sign in to comment.