-
-
Notifications
You must be signed in to change notification settings - Fork 358
Fix and_call_original for Ruby 3.2 #1552
Fix and_call_original for Ruby 3.2 #1552
Conversation
|
||
it 'works for the method propagated by method missing' do | ||
expect(instance).to receive(:existing_method).with(:arg, kwarg: 1).and_call_original | ||
expect(instance.existing_method(:arg, kwarg: 1)).to eq([:arg, 1]) |
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 test actually reproduces the error in Ruby 3.2
Failure/Error:
def existing_method_with_args(arg, kwarg:)
[arg, kwarg]
end
ArgumentError:
wrong number of arguments (given 2, expected 1; required keyword: kwarg)
623ee32
to
fa671b0
Compare
def existing_method_with_args(arg, kwarg:) | ||
[arg, kwarg] | ||
end | ||
|
||
def method_missing(name, *args, **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.
You'll need to eval these from strings conditionally to pass our build
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.
@JonRowe thanks, done! Let's see if it helps 👍
fa671b0
to
e262bf4
Compare
if name.to_s == "greet_jack" | ||
"Hello, jack" | ||
elsif name.to_s == "method_with_kwarg" | ||
call_method_with_kwarg(*args, **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.
This will also need to be wrapped to pass our build, until we release RSpec 4 we support pre keyword rubies (sorry)
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.
@JonRowe ah, got it, I've changed the code, and now all the new examples are evaluated conditionally 👍
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.
Ruby 2.0 failed because the kwarg doesn't have a default value, I changed the condition to run only when required-kwarg are available. Hope it will pass now
828ba9d
to
f43911b
Compare
When the original method isn't present, a proc that sends method_missing is returned. This block must support ruby2_keywords in order to work correctly with Ruby 3.2
f43911b
to
c926345
Compare
Thanks! |
…-method-double Fix and_call_original for Ruby 3.2
Released in 3.12.6 |
When the original method isn't present, a proc that sends method_missing is returned. This block must support ruby2_keywords in order to work correctly with Ruby 3.2.
Otherwise, the following error is raised