rspec-support icon indicating copy to clipboard operation
rspec-support copied to clipboard

[bugfix] Properly detect kwargs hashes vs optional positional args

Open malcolmohare opened this issue 1 year ago • 2 comments

Attempting to fix https://github.com/rspec/rspec-expectations/issues/1451

Refactor has_kw_args_in?:

  • try to use positional parameter information to determine whether a hash is kw_args
  • try to leverage information passed by the ruby2_keywords annotation
  • fallback to inspection of keyword args to determine if they look valid or not

Added backwards compatible ruby2_keywords wrapping to the necessary methods (valid? and error_for) in the spec files like so: ruby2_keywords(:valid?) if respond_to?(:ruby2_keywords, true)

Also needed to modify how args are passed to the MSV split_args so that the special kwargs markings are not lost.

malcolmohare avatar Feb 25 '24 04:02 malcolmohare

Fails on Ruby 3+

pirj avatar Feb 25 '24 08:02 pirj

Fully backwards compatible, just need to fix 3.2 and up. The behavior of ruby2_keywords changed between 3.1 and 3.2: https://rubyreferences.github.io/rubychanges/3.2.html#keyword-argument-separation-leftovers

malcolmohare avatar Feb 27 '24 16:02 malcolmohare

Apologies I never got round to looking at this, I've migrated it over to the monorepo as rspec/rspec#121 I'm hoping to do a big refactoring of keyword argument support with RSpec 4 dropping older ruby support.

JonRowe avatar Nov 30 '24 11:11 JonRowe