Skip to content

Commit

Permalink
move Mockery#stub_method call to ObjectMethods
Browse files Browse the repository at this point in the history
Mock wasn't the right place for calling it. The new yield mechanism is
more general and less ugly, and allocates responsibilities more
appropriately.
  • Loading branch information
nitishr committed Feb 20, 2020
1 parent 583103b commit 5222998
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ def any_expectations?
end

# @private
def anticipates(method_name_or_hash, backtrace = nil, object = Mock.new(@mockery))
def anticipates(method_name_or_hash, backtrace = nil, &block)
ExpectationSetting.new(Array(method_name_or_hash).map do |*args|
args = args.flatten
method_name = args.shift
Mockery.instance.stub_method(object, method_name) unless object.is_a?(Mock)
yield method_name if block
ensure_method_not_already_defined(method_name)
expectation = Expectation.new(self, method_name, backtrace)
expectation.returns(args.shift) unless args.empty?
Expand Down
4 changes: 3 additions & 1 deletion lib/mocha/object_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ 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, self)
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 5222998

Please sign in to comment.