Skip to content

Commit

Permalink
Avoid arity check in Mock#respond_to_missing?
Browse files Browse the repository at this point in the history
As far as I can see, Object#respond_to? has supported an optional 2nd
argument since at least Ruby v1.8.6 and perhaps forever. The only thing
thing that changed was that in Ruby v2 onwards the optional 2nd argument
changed its name from include_private to include_all. I'm not sure
whether this was just a clarification about the behaviour for protected
methods or whether prior to v2 protected methods were never checked.

In any case, it seems to make sense to assume that a respond_to? method
always supports an optional 2nd argument and avoid the arity check in
Mock#respond_to_missing?. My suspicion is that this check was only added
to avoid having to fix some tests in MockTest which I've since resolved
in an earlier commit.
  • Loading branch information
floehopper committed Aug 15, 2022
1 parent 2041129 commit 365a734
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,7 @@ def method_missing(symbol, *arguments, &block) # rubocop:disable Style/MethodMis
# @private
def respond_to_missing?(symbol, include_private = false)
if @responder
if @responder.method(:respond_to?).arity > 1
@responder.respond_to?(symbol, include_private)
else
@responder.respond_to?(symbol)
end
@responder.respond_to?(symbol, include_private)
else
@everything_stubbed || all_expectations.matches_method?(symbol)
end
Expand Down

0 comments on commit 365a734

Please sign in to comment.