Skip to content

Commit 5222998

Browse files
committed
move Mockery#stub_method call to ObjectMethods
Mock wasn't the right place for calling it. The new yield mechanism is more general and less ugly, and allocates responsibilities more appropriately.
1 parent 583103b commit 5222998

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: lib/mocha/mock.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ def any_expectations?
357357
end
358358

359359
# @private
360-
def anticipates(method_name_or_hash, backtrace = nil, object = Mock.new(@mockery))
360+
def anticipates(method_name_or_hash, backtrace = nil, &block)
361361
ExpectationSetting.new(Array(method_name_or_hash).map do |*args|
362362
args = args.flatten
363363
method_name = args.shift
364-
Mockery.instance.stub_method(object, method_name) unless object.is_a?(Mock)
364+
yield method_name if block
365365
ensure_method_not_already_defined(method_name)
366366
expectation = Expectation.new(self, method_name, backtrace)
367367
expectation.returns(args.shift) unless args.empty?

Diff for: lib/mocha/object_methods.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def anticipates(expected_methods_vs_return_values)
147147
if frozen?
148148
raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
149149
end
150-
mocha.anticipates(expected_methods_vs_return_values, caller, self)
150+
mocha.anticipates(expected_methods_vs_return_values, caller) do |method_name|
151+
Mockery.instance.stub_method(self, method_name)
152+
end
151153
end
152154
end
153155
end

0 commit comments

Comments
 (0)