Skip to content

Commit caea3a3

Browse files
committed
Refactor: inline anticipates into expects
This reduces the surface area of the internal API exposed to users as suggested in #467
1 parent 55fc710 commit caea3a3

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/mocha/object_methods.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def stubba_method_for(method_name)
7373
#
7474
# @see Mock#expects
7575
def expects(expected_methods_vs_return_values)
76-
anticipates(expected_methods_vs_return_values)
76+
if frozen?
77+
raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
78+
end
79+
mocha.anticipates(expected_methods_vs_return_values, caller) do |method_name|
80+
Mockery.instance.stub_method(self, method_name)
81+
end
7782
end
7883

7984
# 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)
105110
#
106111
# @see Mock#stubs
107112
def stubs(stubbed_methods_vs_return_values)
108-
anticipates(stubbed_methods_vs_return_values).at_least(0)
113+
expects(stubbed_methods_vs_return_values).at_least(0)
109114
end
110115

111116
# 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)
137142
mockery.stubba.unstub(stubba_method_for(method_name))
138143
end
139144
end
140-
141-
private
142-
143-
def anticipates(expected_methods_vs_return_values)
144-
if frozen?
145-
raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
146-
end
147-
mocha.anticipates(expected_methods_vs_return_values, caller) do |method_name|
148-
Mockery.instance.stub_method(self, method_name)
149-
end
150-
end
151145
end
152146
end

0 commit comments

Comments
 (0)