From caea3a3c9de9e0197ad9ce2f7725ce08b7ed6f2b Mon Sep 17 00:00:00 2001 From: Nitish Rathi Date: Fri, 21 Feb 2020 12:38:14 +0000 Subject: [PATCH] Refactor: inline anticipates into expects This reduces the surface area of the internal API exposed to users as suggested in #467 --- lib/mocha/object_methods.rb | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/mocha/object_methods.rb b/lib/mocha/object_methods.rb index cb3e6f8a6..968b4f66b 100644 --- a/lib/mocha/object_methods.rb +++ b/lib/mocha/object_methods.rb @@ -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. @@ -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. @@ -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