-
-
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
Keyword argument warning on Ruby 2.7 for #and_call_original #1306
Comments
@jaynetics sorry it took so long but #1324 should take of this warning |
Any news on this one? |
@jonspalmer Thanks for the reminder! |
Any further news on this? We'd like to get on Ruby 2.7.1 and this is the only "blocker" (not a showstopper, but would be nice to have resolved). |
The same issue, any updates? |
Its on the list of things the team are working on and as always PRs are welcome. |
It looks like this is now broken on Ruby 3. I'm happy to take a look, but I guess I don't know what the current status is. |
@ioquatix No work is done on this front yet, we're focusing on preparing 4.0 release. Would be happy to include kwargs delegation fixes along with it. If you can spare some time, here are notable things to get you going. Most importantly, it seems that using |
Work has been done on this but it slipped through the cracks, in part because we don't have specs for a lot of the keyword argument usage. Any keyword argument specs that can be provided which now fail I'll happily fix and take priority over releasing RSpec 4 so people can use Ruby 3 while we work on it. |
@ioquatix Have you had a chance to take a look? No stress, we're going to pair on this with @benoittgt, just to avoid doing duplicate work. |
Applying this demonstrates the issue: --- a/spec/rspec/mocks/and_call_original_spec.rb
+++ b/spec/rspec/mocks/and_call_original_spec.rb
@@ -12,6 +12,10 @@ RSpec.describe "and_call_original" do
yield x, :additional_yielded_arg
end
+ if RSpec::Support::RubyFeatures.kw_args_supported?
+ class_eval("def meth_3(a: ''); a; end")
+ end
+
def self.new_instance
new
end
@@ -59,6 +63,12 @@ RSpec.describe "and_call_original" do
expect(value).to eq([:submitted_arg, :additional_yielded_arg])
end
+ it 'supports keyword arguments' do
+ expect(instance).to receive(:meth_3).and_call_original
+ value = instance.meth_3(a: :a)
+ expect(value).to eq(:a)
+ end
+ |
(Or at least it generates the warning, I can't run rspec-mocks on Ruby 3.0.0 locally at the moment due to a |
I have not had time to look into it yet so thank you for your efforts. |
rspec-mocks is having some trouble with regard to keyword arguments when using and_call_original: [rspec/rspec-mocks#1306](rspec/rspec-mocks#1306) There was just 1 failing spec due to this, and we actually do not need to call orginals in this cases.
rspec-mocks is having some trouble with regard to keyword arguments when using and_call_original: [rspec/rspec-mocks#1306](rspec/rspec-mocks#1306) There was just 1 failing spec due to this, and we actually do not need to call orginals in this cases.
rspec-mocks is having some trouble with regard to keyword arguments when using and_call_original: [rspec/rspec-mocks#1306](rspec/rspec-mocks#1306) There was just 1 failing spec due to this, and we actually do not need to call orginals in this cases.
double |
Done! #1396 --for the history: the bad guy is |
✅ Locally, for Ruby <= 2.7.2 specs are all passing ❌ For Ruby 3.0 some specs are failing. All errors seem to be related to the changed behavior for kwargs -> **update**: see comments below! ``` Finished in 19.31 seconds (files took 0.67243 seconds to load) 123 examples, 7 failures Failed examples: rspec ./spec/zip_tricks/block_deflate_spec.rb:46 # ZipTricks::BlockDeflate deflate_in_blocks_and_terminate uses deflate_in_blocks rspec ./spec/zip_tricks/block_deflate_spec.rb:58 # ZipTricks::BlockDeflate deflate_in_blocks_and_terminate passes a custom compression level rspec ./spec/zip_tricks/block_deflate_spec.rb:87 # ZipTricks::BlockDeflate.deflate_in_blocks honors the block size rspec ./spec/zip_tricks/rails_streaming_spec.rb:4 # ZipTricks::RailsStreaming calls the requisite controller methods rspec ./spec/zip_tricks/streamer_spec.rb:276 # ZipTricks::Streamer writes the correct archive elements when using data descriptors rspec ./spec/zip_tricks/streamer_spec.rb:420 # ZipTricks::Streamer prevents duplicates in the stored files rspec ./spec/zip_tricks/streamer_spec.rb:525 # ZipTricks::Streamer writes the specified modification time ``` -> I've added a new issue to address the actual fixes for Ruby 3 in a separated PR: #104 **update** the actual problem (for the first spec at least) is `rspec-mocks`, in particular this line: https://github.com/rspec/rspec-mocks/blob/6ab343ca479c606e892c82ce0245e7410e3f0eac/lib/rspec/mocks/message_expectation.rb#L101 ```ruby def and_call_original wrap_original(__method__) do |original, *args, &block| original.call(*args, &block) end end ``` which will receive the following `args`: ```ruby [#<StringIO:0x00007ff8d713bfc8>, #<StringIO:0x00007ff8d713be88>, {:level=>-1, :block_size=>65536}] ``` hence this is expanded to 3 params, 2x a string, and a hash, which is then not splatted into kwargs. Further research shows, there is already an Issue: rspec/rspec-mocks#1306 with a fixing PR: rspec/rspec-mocks#1324
✅ Locally, for Ruby <= 2.7.2 specs are all passing ❌ For Ruby 3.0 some specs are failing. All errors seem to be related to the changed behavior for kwargs -> **update**: see comments below! ``` Finished in 19.31 seconds (files took 0.67243 seconds to load) 123 examples, 7 failures Failed examples: rspec ./spec/zip_tricks/block_deflate_spec.rb:46 # ZipTricks::BlockDeflate deflate_in_blocks_and_terminate uses deflate_in_blocks rspec ./spec/zip_tricks/block_deflate_spec.rb:58 # ZipTricks::BlockDeflate deflate_in_blocks_and_terminate passes a custom compression level rspec ./spec/zip_tricks/block_deflate_spec.rb:87 # ZipTricks::BlockDeflate.deflate_in_blocks honors the block size rspec ./spec/zip_tricks/rails_streaming_spec.rb:4 # ZipTricks::RailsStreaming calls the requisite controller methods rspec ./spec/zip_tricks/streamer_spec.rb:276 # ZipTricks::Streamer writes the correct archive elements when using data descriptors rspec ./spec/zip_tricks/streamer_spec.rb:420 # ZipTricks::Streamer prevents duplicates in the stored files rspec ./spec/zip_tricks/streamer_spec.rb:525 # ZipTricks::Streamer writes the specified modification time ``` -> I've added a new issue to address the actual fixes for Ruby 3 in a separated PR: WeTransfer/zip_tricks#104 **update** the actual problem (for the first spec at least) is `rspec-mocks`, in particular this line: https://github.com/rspec/rspec-mocks/blob/6ab343ca479c606e892c82ce0245e7410e3f0eac/lib/rspec/mocks/message_expectation.rb#L101 ```ruby def and_call_original wrap_original(__method__) do |original, *args, &block| original.call(*args, &block) end end ``` which will receive the following `args`: ```ruby [#<StringIO:0x00007ff8d713bfc8>, #<StringIO:0x00007ff8d713be88>, {:level=>-1, :block_size=>65536}] ``` hence this is expanded to 3 params, 2x a string, and a hash, which is then not splatted into kwargs. Further research shows, there is already an Issue: rspec/rspec-mocks#1306 with a fixing PR: rspec/rspec-mocks#1324
Subject of the issue
#and_call_original
with keyword arguments causes the following warning:Your environment
Steps to reproduce
Expected behavior
No warning is emitted.
Actual behavior
A warning is emitted.
The text was updated successfully, but these errors were encountered: