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

Ruby 3+ causes an empty diff error when using `expect .... to receive`

Open luke-hill opened this issue 3 years ago • 4 comments

Subject of the issue

I'm running CI. ~When using ruby3 I get a weird error I'm struggling to triage. I'm 99% certain I'm doing something wrong~

When using ruby3, the keyword args vs hashable args isn't being picked up from rspec expectations. Maybe add a line in to the debug message advising people to check this?

Your environment

  • Ruby version: 3+
  • rspec-expectations version: Latest

Steps to reproduce

View this CI run: https://github.com/site-prism/site_prism/runs/6226827374?check_suite_focus=true

Expected behavior

Ruby 3 doesn't give an error, or if I've done something wrong I know what to fix... EDIT: This is caused by the hashable args issue / keyword issue.

Actual behavior

Related to https://github.com/rspec/rspec-expectations/issues/123 We get a diff where there is no error One specific example is....

  expected: (".class-one", {:css=>".my-css", :text=>"Hi", :wait=>0})
       got: (".class-one", {:css=>".my-css", :text=>"Hi", :wait=>0})
Diff:

Suggested solution

  expected: (".class-one", {:css=>".my-css", :text=>"Hi", :wait=>0})
       got: (".class-one", {:css=>".my-css", :text=>"Hi", :wait=>0})
Diff:
**You are running Ruby 3+ and have an empty diff. Please check your keyword args are matched up correct and convert them to a hash if the method expects a hash**

luke-hill avatar Apr 29 '22 12:04 luke-hill

:wave: We're aware, there a couple of similar issues surrounding diffing keyword hashes vs normal hashes. We're working on it :)

JonRowe avatar Apr 29 '22 20:04 JonRowe

Great to hear. I did manage to fix my bug luckily. Just yeh keep up the great work!

luke-hill avatar May 03 '22 09:05 luke-hill

I am getting this error now. What is the solution?

chrisg220 avatar Jan 31 '23 22:01 chrisg220

The solution is to "check" manually whether your hashing the kwargs correctly.

I use the term solution because it's actually broken. I.e. your tests are failing validly. Because you've made a user error. Just that rspec doesn't highlight this error nicely.

luke-hill avatar Feb 01 '23 11:02 luke-hill

I think this was actually completed, because we now differentiate between keywords and hashes in diffs but if its not please re-open against the monorepo.

JonRowe avatar Nov 27 '24 22:11 JonRowe