-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Version 3.11.2 issue with kwargs #1492
Comments
I have a similar issue when mocking a File.read for a test. The 'allow' is acting like an 'expect' and preventing all other uses of File.read that are not specifically mocked. allow(File).to receive(:read).with('myfile').and_return('my file contents') Then prevents all other uses of File.read. I can work around this by first including allow(File).to receive(:read).and_call_original |
This seems like an unrelated issue @btalbot .Can you please open a separate issue providing a reproduction example? |
@vibro Thanks for reporting.
What was the previous version of |
I have a similar issue. Version 3.11.1 works without errors |
@vibro At a glance, I could find #1394. Could you read comments there to see if there's an explanation to this behavioural change. @rus-max What is the Ruby version that you're using? Can you provide an example of your code? I don't understand if "similar" refers to kwargs or |
ruby 3.1.2
|
Make sure you are not passing hashes as kwargs, this is not valid on Ruby 3 and is now detected correctly (but the diff doesn't show the delta correctly on 3.11, that will come in a minor version bump) |
3.11.1 works just fine. I can update the code/change the behavior but this isn't something I would expect to change/break in a patch release. |
Our support for keyword arguments isn't as good as it could be, a lot of usage such as yours has historically just worked due to implementation details of Ruby (mainly that keyword arguments carried over in splats and thus allowed usage in method calls and blocks transparently) with a bunch of edge case uses not being tested due to maintainers (including myself) not invisioning how they were used. In Ruby 3 that changed and theres has had to be changes (which are mostly investigating and declaring ruby2_keywords correctly) to allow proper keyword arguments to be verified and treated differently to hashes (as in Ruby 3 you cannot mix splats). In this case it appears that
So its non standard to be passing keyword arguments to via
I would accept a PR helping to improve that detection. |
Oddly I can't replicate this within our test suite on either Edit: Removed output showing the snippet didn't work, it needed this adding for reproduction:
An even futher odditiy is it seems to be specifically the |
I can confirm we have this in our spec helper:
|
delegate({}) # => [{}] in Ruby 2.6 & 3, but [] in Ruby 2.7! (with a warning) See the famous blog post. In Ruby 2.7: def foo(*args)
puts args.inspect
end
foo(**{}) # outputs `[]`
have_received(:start).with(host, user, **kwargs) it the same as have_received(:start).with(host, user) But since the original method is defined with According to I've debugged this a bit, and it seems that the This has already been fixed here. But something else was fixed along the way, and the failure on
|
Version 3.11.2 issue with kwargs
Today our CI started failing with the new version of rspec-mocks released. It seems that mocking the kwargs no longer has the same behavior
Your environment
Steps to reproduce
I've provided a sample that is close to the behavior in our tests:
Expected behavior
Previously, this test ran ok.
Actual behavior
Now, we get a mocking error:
The text was updated successfully, but these errors were encountered: