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

Fix with for instance doubles didn't verify Ruby 3 keyword arguments #1473

Merged
merged 2 commits into from
May 28, 2022
Merged
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 lib/rspec/mocks/verifying_message_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def with(*args, &block)
end
end
end
ruby2_keywords(:with) if respond_to?(:ruby2_keywords, true)

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ module Mocks
}.to raise_error(ArgumentError, /no_args/)
end
end

if RSpec::Support::RubyFeatures.required_kw_args_supported?
context "for a method with keyword args" do
it "matches against a hash submitted as keyword arguments and received as positional argument (in both Ruby 2 and Ruby 3)" do
expect(dbl).to receive(:kw_args_method).with(1, {:required_arg => 2, :optional_arg => 3})
dbl.kw_args_method(1, :required_arg => 2, :optional_arg => 3)
end

if RUBY_VERSION >= "3"
it "fails to match against a hash submitted as a positional argument and received as keyword arguments in Ruby 3.0 or later", :reset => true do
expect(dbl).to receive(:kw_args_method).with(1, :required_arg => 2, :optional_arg => 3)
expect do
dbl.kw_args_method(1, {:required_arg => 2, :optional_arg => 3})
end.to fail_with(a_string_including("expected: (1, {:optional_arg=>3, :required_arg=>2}) (keyword arguments)", "got: (1, {:optional_arg=>3, :required_arg=>2}) (options hash)"))
end
else
it "matches against a hash submitted as a positional argument and received as keyword arguments in Ruby 2.7 or before" do
expect(dbl).to receive(:kw_args_method).with(1, :required_arg => 2, :optional_arg => 3)
dbl.kw_args_method(1, {:required_arg => 2, :optional_arg => 3})
end
end
end
end
end
end
end
Expand Down