rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 357 forks source link

Reproduction case for Ruby 3.2 and kwargs detection #1497

Closed pirj closed 1 year ago

pirj commented 1 year ago

Related to #1495

pirj commented 1 year ago

@eregon Do you happen to know what might have caused the failures on 3.2.0-preview2 and ruby-head while passed just fine with 3.1?

Is this still correct for Ruby 3.2?


        if RSpec::Support::RubyFeatures.distincts_kw_args_from_positional_hash? && expected_args == actual_args
          expected_hash = expectation.expected_args.last
          actual_hash = args_for_multiple_calls.last.last
          if Hash === expected_hash && Hash === actual_hash &&
            (Hash.ruby2_keywords_hash?(expected_hash) != Hash.ruby2_keywords_hash?(actual_hash))
            actual_args += Hash.ruby2_keywords_hash?(actual_hash) ? " (keyword arguments)" : " (options hash)"
            expected_args += Hash.ruby2_keywords_hash?(expected_hash) ? " (keyword arguments)" : " (options hash)"
          end
        end

2.2 failure is unrelated, to be fixed by #1498

eregon commented 1 year ago

That code looks fine. I suspect it's a missing ruby2_keywords on the chain of calls, and so the flag is lost somewhere. You can debug by printing Hash.ruby2_keywords_hash?(h) before the exception happens.

eregon commented 1 year ago

And 3.2 fixes a bug where some missing ruby2_keywords accidentally kept the flag: https://github.com/ruby/ruby/blob/master/NEWS.md

pirj commented 1 year ago

Thank you so much for the explanation, @eregon !

pirj commented 1 year ago

Superseded by #1514