Skip to content

Commit

Permalink
fixup! WIP: Handle Array#flatten in Ruby v2.0-v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Dec 28, 2022
1 parent 43aa8a2 commit fce1211
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,13 @@ def raise_unexpected_invocation_error(invocation, matching_expectation)
end

def check_responder_responds_to(symbol)
if @responder && (!@responder.respond_to?(symbol, true) || (!RUBY_V23_PLUS && (symbol == :to_ary) && !@responder.respond_to?(symbol))) # rubocop:disable Style/GuardClause
raise NoMethodError, "undefined method `#{symbol}' for #{mocha_inspect} which responds like #{@responder.mocha_inspect}"
end
return unless @responder

legacy_behaviour_for_array_flatten = !RUBY_V23_PLUS && !@responder.respond_to?(symbol) && (symbol == :to_ary)

return if @responder.respond_to?(symbol, true) && !legacy_behaviour_for_array_flatten

raise NoMethodError, "undefined method `#{symbol}' for #{mocha_inspect} which responds like #{@responder.mocha_inspect}"
end

def check_expiry
Expand Down

0 comments on commit fce1211

Please sign in to comment.