-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Regression in rspec-expectations 3.9.3 if argument to predicate method implements to_hash #1221
Comments
Can you provide a minimal reproduction in this issue? |
Yes, it's in the "Steps to reproduce" section above. |
We started seeing this today as well. Here is a simple example to reproduce the issue with rspec 3.9.3. With 3.9.3, the first test case fails: RSpec.describe "hash equality" do
it "can assert equality of empty hashes" do
expect(Hash.new).to be_eql(Hash.new)
end
it "can assert equality of non-empty hashes" do
expect({ foo: "bar" }).to be_eql({ foo: "bar" })
end
it "can assert non-equality of non-empty hashes" do
expect({ foo: "bar" }).not_to be_eql({ foo: "baz" })
end
end |
@joshcooper for future reference, please just provide a snippet directly in the issue, don't link unless its a complicated reproduction. |
ah, sure thing 👍 |
This is really problematic, we are receiving this arg as edit Indeed, in Ruby 3 this problem goes away because of the hard split on hash like keyword arguments, so we could revert the fix for the warning with the knowledge we cannot fix it... |
There is a regression with keyword args[1], exclude that version. [1] rspec/rspec-expectations#1221
Wouldn't |
My experiments with |
See https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#a-compatible-delegation, the target method does not need |
@JonRowe I prototyped a fix, this passes
Currently RSpec seems to use an approach based on a version check like https://eregon.me/blog/2019/11/10/the-delegation-challenge-of-ruby27.html#version-check-with-ruby-2--ruby-3-style-delegation, but that unfortunately does not work for 2.7 for which neither |
With #1222 I can no longer reproduce the issue. |
This has been released as 3.9.4 can you upgrade @joshcooper ? |
Issue is resolved using 3.9.4. Thanks @JonRowe! |
Thank you, I've got same troubles as OP with 3.9.3 and can confirm issue is fixed in 3.9.4 |
Subject of the issue
Our spec tests starting failing with the latest rspec-expectations 3.9.3 release due to keyword argument handling changes.
Your environment
Steps to reproduce
Expected behavior
When an object is passed to the
be_xxx
predicate matcher, it should be passed through unchanged to the predicate method.Actual behavior
Something in rspec's keyword argument handling results in the object's
to_hash
method getting called, the value of which is passed to the predicate method instead of the original object. Note in the test how https://github.com/joshcooper/betest/blob/680b6489441f1f0dc1f5e2d55332d449e391343b/spec/betest_spec.rb#L22 passes but https://github.com/joshcooper/betest/blob/680b6489441f1f0dc1f5e2d55332d449e391343b/spec/betest_spec.rb#L26 fails becauseB
implementsto_hash
.Downgrading to rspec-expectations 3.9.2 works around the problem
The text was updated successfully, but these errors were encountered: