-
-
Notifications
You must be signed in to change notification settings - Fork 358
Confused over instance doubles, keyword args, with, and Ruby 3.2 previews #1495
Comments
It sounds like Ruby 3.2 has changed something that has broken our detection between keywords and hashes again, wether that fix needs to go into Ruby or us depends on if it was a deliberate change on their side or an accidental one. |
It's likely due to this change, search for |
diff --git a/lib/rspec/mocks/verifying_proxy.rb b/lib/rspec/mocks/verifying_proxy.rb
index b39871c8..1d8d207d 100644
--- a/lib/rspec/mocks/verifying_proxy.rb
+++ b/lib/rspec/mocks/verifying_proxy.rb
@@ -160,6 +160,7 @@ module RSpec
validate_arguments!(args)
super
end
+ ruby2_keywords :proxy_method_invoked if respond_to?(:ruby2_keywords, true)
def validate_arguments!(actual_args)
@method_reference.with_signature do |signature| fixes class Xxx
def self.x(extra:)
end
end
RSpec.describe 'ruby-3.2.0' do
specify do
allow(Xxx).to receive(:x).with(extra: {})
Xxx.x(extra: {})
end
specify do
expect(Xxx).to receive(:x).with(extra: {})
Xxx.x(extra: {})
end
end for me (and CI for some small internal project) |
With the change above testsuite passes except reentrant mutext inside the Fiber spec, see ruby/ruby#6680 (comment) |
Would you like to send a PR, @ojab ? |
@pirj sure, I just want to get some clarification on ruby/ruby#6680 (comment) first. |
As I replied there, I think the best is to adjust that spec: ruby/ruby#6680 (comment) |
We have a |
@pirj yep, ruby-head is fine too. |
…onfusion Ruby 3.2.0 preview2 broke how rspec 3.12 detects if a method takes keyword arguments or hashes[1]. For now, mark the tests as pending. [1] rspec/rspec-mocks#1495
I found another place we need to instrument a method via I almost wonder if we should just audit all methods that have a |
I did that for some gems, yes it's a good idea to audit all
Indeed it's not semantically harmful to add |
Subject of the issue
I ran a bunch of specs on my project through GitHub actions and a bunch failed recently against Ruby head. I'm not sure whether it's the fault of Ruby or RSpec or my own misunderstanding, so I thought I would report it here first.
The issue came down to expectations for instance doubles for objects that take keyword arguments and how to test them. Please see the steps to reproduce below for details.
Your environment
Steps to reproduce
Expected behavior
I expected the first test to pass, since the expectation is that the method is called with two keyword arguments and then the method is called with two keyword arguments.
I'd expect the second test to fail because the expectation is that the method is called with a hash, but the method is called with keyword arguments.
Actual behavior
The first test fails and the second passes.
However, just to throw some extra information in:
Is this something that should be raised with Ruby or is it something that RSpec needs to handle for Ruby 3.2?
The text was updated successfully, but these errors were encountered: