Skip to content

Commit

Permalink
Extract handle_method_call from method_missing
Browse files Browse the repository at this point in the history
Continues the refactoring started in #549 on the road to better keyword
args matching. This is part of a refactor sketched out in #544.

The key change is to pass arguments and the block directly instead of
re-splatting them. That way, we would only need to set ruby2_keywords at
the edges, instead of with each splat (for contrast, see the initial
spike in #534, where ruby2_keywords had to be set at multiple layers).

The extracting of handle_method_call is not strictly necessary, but it
makes it clearer that method_missing is just one of the possible entry
points for a method call.
  • Loading branch information
wasabigeek authored and floehopper committed Sep 17, 2022
1 parent 24d3cfb commit 6a09a37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ def all_expectations

# @private
def method_missing(symbol, *arguments, &block) # rubocop:disable Style/MethodMissingSuper
handle_method_call(symbol, arguments, block)
end

# @private
def handle_method_call(symbol, arguments, block)
check_expiry
check_responder_responds_to(symbol)
invocation = Invocation.new(self, symbol, arguments, block)
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/stubbed_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def define_new_method
self_in_scope = self
method_name_in_scope = method_name
stub_method_owner.send(:define_method, method_name) do |*args, &block|
self_in_scope.mock.method_missing(method_name_in_scope, *args, &block)
self_in_scope.mock.handle_method_call(method_name_in_scope, args, block)
end
retain_original_visibility(stub_method_owner)
end
Expand Down

0 comments on commit 6a09a37

Please sign in to comment.