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

Fix keyword arguments in dynamic method dispatch #2509

Closed

Commits on Jul 15, 2021

  1. Fix keyword arguments in dynamic matchers

    Ruby 3 changed the way keyword arguments work.
    Currently, to forward arguments, the only way that works in Ruby 2.6, 2.7, and 3.0,
    is to call `ruby2_keywords :method_name` for the method that receives the arguments.
    
    This will cause Ruby to remember that the final hash was created by keyword arguments,
    and then when expanding out the arguments later, eg [here](https://github.com/rspec/rspec-expectations/blob/43bf64b01f8356979ffbc373b2e81d2ab1389b29/lib/rspec/matchers/built_in/has.rb#L67),
    it will see that the last element was created by keywords, and it will pass that into
    the keywords area of a method infocation.
    
    If we don't do this, it will consider it an ordinal argument and not line it up with
    the keywords. This typically causes a "wrong number of arguments" error, because it's
    passing an extra ordinal argument.
    
    Here is another example from within RSpec, where they have arrived at this solution
    for the same problem: https://github.com/rspec/rspec-expectations/blob/43bf64b01f8356979ffbc373b2e81d2ab1389b29/lib/rspec/matchers/dsl.rb#L538-L540
    JoshCheek committed Jul 15, 2021
    Copy the full SHA
    ec244b0 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    e4b3953 View commit details
    Browse the repository at this point in the history

Commits on Jul 27, 2021

  1. Update spec/rspec/rails/example/controller_example_group_spec.rb

    Co-authored-by: Jon Rowe <mail@jonrowe.co.uk>
    pirj and JonRowe committed Jul 27, 2021
    Copy the full SHA
    e2541f0 View commit details
    Browse the repository at this point in the history
  2. Update spec/rspec/rails/example/controller_example_group_spec.rb

    Co-authored-by: Jon Rowe <mail@jonrowe.co.uk>
    pirj and JonRowe committed Jul 27, 2021
    Copy the full SHA
    cb7e2d4 View commit details
    Browse the repository at this point in the history
  3. Revert the previous spec change

    pirj committed Jul 27, 2021
    Copy the full SHA
    0b74226 View commit details
    Browse the repository at this point in the history