Skip to content
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

Reproduction case for Ruby 3.2 and kwargs detection #1497

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
strategy:
matrix:
ruby:
- '3.2.0-preview2'
- '3.1'
- '3.0'
- 2.7
Expand Down
26 changes: 26 additions & 0 deletions spec/rspec/mocks/matchers/receive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ module Mocks
end
end

# FIXME: this is defined here to prevent
# "warning: method redefined; discarding old kw_args_method"
# because shared examples are evaluated several times.
# When we flatten those shared examples in RSpec 4 because
# of no "should" syntax, it will become possible to put this
# class definition closer to examples that use it.
if RSpec::Support::RubyFeatures.required_kw_args_supported?
binding.eval(<<-RUBY, __FILE__, __LINE__)
class TestObject
def kw_args_method(a:, b:); end
end
RUBY
end

shared_examples "a receive matcher" do |*options|
it 'allows the caller to configure how the subject responds' do
wrapped.to receive(:foo).and_return(5)
Expand Down Expand Up @@ -109,6 +123,18 @@ module Mocks

expect(receiver.foo(kw: :arg)).to eq(:arg)
end

it "expects to receive keyword args" do
dbl = instance_double(TestObject)
expect(dbl).to receive(:kw_args_method).with(a: 1, b: 2)
dbl.kw_args_method(a: 1, b: 2)
end

it "expects to receive keyword args with a hash" do
dbl = instance_double(TestObject)
expect(dbl).to receive(:kw_args_method).with({a: 1, b: 2})
dbl.kw_args_method(a: 1, b: 2)
Comment on lines +135 to +136
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this expected to fail? It expects a positional Hash but is given kwargs.
But I guess expect(dbl).to receive actually creates a method with no kwargs so then it should pass?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indeed should have failed on earlier Ruby versions, too.

end
RUBY
end
end
Expand Down