This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 358
Fix argument forwarding for "receive" with Ruby 3.2.0 #1514
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ jobs: | |
strategy: | ||
matrix: | ||
ruby: | ||
- '3.2' | ||
- '3.1' | ||
- '3.0' | ||
- 2.7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fail, shouldn't it? We expect an options hash, and pass kwargs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I am wondering if it is a side effect of changes in 3.2. Like on release note. @eregon any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to be in the opposite situation when an option hash passed as a positional argument to an expectation suddenly matches with a kwargs hash.
I suppose that the problem is here:
In our scenario,
Hash.ruby2_keywords_hash?(actual_args.last)
istrue
, while the other one isfalse
.They don't match, but we don't return
false
like we do e.g. here:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing this:
This is causing two more specs to fail, at least on Ruby 3.2:
But if we'd make this comparison strict, I agree that it should fail.
Do you guys agree to make such a change, and see if it affects other Rubies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failure message is suboptimal:
while the method was indeed called, and arguments were alike, it's just the
Hash.ruby2_keywords_hash?
that didn't match.We do it better here:
but this differ doesn't seem to come into play.
Might be related: rspec/rspec-support#537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is the comment above:
# if both arguments end with Hashes, and if one is a keyword hash and the other is not, they don't match
is super confusing. That should be updated to something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is only true for methods that accept positional parameters, right? E.g. for:
If we follow
The spec will pass, but the real-life code:
would blow up with:
that means we would be concealing the error.
Is my understanding correct, @eregon ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a mock, so the method might not exist, right?
From
with({a: 1})
that doesn't indicate the method takes keyword arguments, hence it can be called with whatever (passinga: 1
or{a: 1}
shouldn't make any difference).If the method does exist like in that case, I think maybe RSpec could warn that you call
with
without kwargs when the method accepts kwargs.Or, you could actually check whether the existing method accepts kwargs or not for the kwargs-vs-positional check, but then what happens if the method does not exist?
Wouldn't this specific example fail anyway because it actually calls the original method?
And if it doesn't call the original method, isn't it wrong to look at the original method?
EDIT: it indeed does not call the original for
expect(a).to receive(:foo).with({bar: 1})
.That's super confusing to me, it just returns
nil
instead.MSpec would always call the original, unless one uses
.and_return
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this example wouldn't be caught by your change, right? (no ruby2_keyword flag on both sides)
So it's a bug of writing
.with({bar: 1})
which means "expect no kwargs" when the real method only accepts kwargs. Hence maybe that's worth a warning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. The rest makes total sense, too.