diff --git a/lib/rspec/mocks/argument_list_matcher.rb b/lib/rspec/mocks/argument_list_matcher.rb index be5869027..7b2a41f45 100644 --- a/lib/rspec/mocks/argument_list_matcher.rb +++ b/lib/rspec/mocks/argument_list_matcher.rb @@ -63,7 +63,7 @@ def args_match?(*actual_args) if Hash.respond_to?(:ruby2_keywords_hash?, true) # if both arguments end with Hashes, and if one is a keyword hash and the other is not, they don't match if Hash === expected_args.last && Hash === actual_args.last - if Hash.ruby2_keywords_hash?(actual_args.last) != Hash.ruby2_keywords_hash?(expected_args.last) + if !Hash.ruby2_keywords_hash?(actual_args.last) && Hash.ruby2_keywords_hash?(expected_args.last) return false end end diff --git a/spec/rspec/mocks/argument_matchers_spec.rb b/spec/rspec/mocks/argument_matchers_spec.rb index acdc76f03..3bf679066 100644 --- a/spec/rspec/mocks/argument_matchers_spec.rb +++ b/spec/rspec/mocks/argument_matchers_spec.rb @@ -381,20 +381,10 @@ def ==(other) a_double.random_call(:a => "a", :b => "b") end - if RSpec::Support::RubyFeatures.required_kw_args_supported? - it "fails to match against a hash submitted by reference and received by value in Ruby 3", :reset => true do - opts = {:a => "a", :b => "b"} - expect(a_double).to receive(:random_call).with(opts) - expect do - a_double.random_call(:a => "a", :b => "b") - end.to fail_with(/expected: \(\{:a=>"a", :b=>"b"|:b=>"b", :a=>"a"\}\)/) - end - else - it "matches against a hash submitted by reference and received by value in Ruby 2" do - opts = {:a => "a", :b => "b"} - expect(a_double).to receive(:random_call).with(opts) - a_double.random_call(:a => "a", :b => "b") - end + it "matches against a hash submitted by reference and received by value (in both Ruby 2 and Ruby 3)" do + opts = {:a => "a", :b => "b"} + expect(a_double).to receive(:random_call).with(opts) + a_double.random_call(:a => "a", :b => "b") end if RUBY_VERSION >= "2.7"