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

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

Open
luke-hill opened this issue Apr 29, 2022 · 4 comments
Open

Comments

@luke-hill
Copy link

luke-hill commented Apr 29, 2022

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 #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**
@JonRowe
Copy link
Member

JonRowe commented Apr 29, 2022

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

@luke-hill
Copy link
Author

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

aramprice added a commit to cloudfoundry/bosh that referenced this issue Sep 19, 2022
In Ruby 3.1 method args must be explicitly wrapped in `{}` in order to
be passed as a `Hash` and not interperated as keword-args.

This commit adds `{}` to various `expect` calls so that RSpec can
correctly validate the expectations.

See also rspec/rspec-expectations#1370
@chrisg220
Copy link

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

@luke-hill
Copy link
Author

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.

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

No branches or pull requests

3 participants