Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't convert keywords to hash in #send for verifying doubles on Ruby 3 #1520

Merged
merged 2 commits into from
Jan 10, 2023

Conversation

pirj
Copy link
Member

@pirj pirj commented Jan 10, 2023

The current re-implementation of send on verifying doubles uses *args by itself. Everything works fine on main for Ruby 2 or lower, but on Ruby 3 this converts keyword arguments to a Hash element inside the args array, which then gets passed to __send__ and then super and (correctly) causes a failure when the method gets a Hash instead of keywords.

Without this patch, the new test passes on Ruby 2.7.6 and fails on Ruby 3.1.2:

Failures:

  1) Expected argument verification (when `#with` is called) when doubling a loaded class for a method with keyword args when using `send` matches against keyword arguments
     Failure/Error: dbl.send(:m, :k => 1)
     
       #<InstanceDouble(#<Class:0x00007fbd16cf1ba8>) (anonymous)> received :m with unexpected arguments
         expected: ({:k=>1}) (keyword arguments)
              got: ({:k=>1}) (options hash)
       Diff:

With this patch, all tests pass on all Ruby versions.

Fixes #1485

@pirj pirj self-assigned this Jan 10, 2023
@pirj pirj requested a review from JonRowe January 10, 2023 12:10
@JonRowe JonRowe merged commit 521db55 into main Jan 10, 2023
@JonRowe JonRowe deleted the ruby3-verifying-double-send-fix branch January 10, 2023 22:04
JonRowe pushed a commit that referenced this pull request Jan 10, 2023
… 3 (#1520)

* Don't convert keywords to hash in #send for verifying doubles on Ruby 3

Co-authored-by: Charlie Honig <chonig@panoramaed.com>
@Laykou
Copy link

Laykou commented Jan 16, 2023

Do you think this could be released as new version?

Currently I had to load from source:

gem 'rspec-rails', '6.1.0.pre', github: 'rspec/rspec-rails', branch: 'main'
gem 'rspec', '3.13.0.pre', github: 'rspec/rspec', branch: 'main'
gem 'rspec-core', '3.13.0.pre', github: 'rspec/rspec-core', branch: 'main'
gem 'rspec-mocks', github: 'rspec/rspec-mocks', branch: 'main'
gem 'rspec-expectations', github: 'rspec/rspec-expectations', branch: 'main'
gem 'rspec-support', github: 'rspec/rspec-support', branch: 'main'

to fix the issue with mocking of method with keyword arguments

@JonRowe
Copy link
Member

JonRowe commented Jan 17, 2023

Released as 3.12.3

@Laykou
Copy link

Laykou commented Jan 17, 2023

Thank you! This resolved the "keyword" argument mock issue in Ruby 3.2 for me. Yay! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants