From 365a7348dbd8e8798584001e261d31a7355c19d8 Mon Sep 17 00:00:00 2001 From: James Mead Date: Mon, 15 Aug 2022 18:13:37 +0100 Subject: [PATCH] Avoid arity check in Mock#respond_to_missing? 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. --- lib/mocha/mock.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/mocha/mock.rb b/lib/mocha/mock.rb index f82121e41..8276ecdbe 100644 --- a/lib/mocha/mock.rb +++ b/lib/mocha/mock.rb @@ -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