Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Support keyword arguments with and_invoke #1595

Merged
merged 2 commits into from
Oct 2, 2024
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
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
### Development
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.13.1...main)

Bug Fixes:

* Support keyword arguments in callables passed to `and_invoke`. (Jon Rowe, #1595)

### 3.13.1 / 2024-05-08
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.13.0...v3.13.1)

Expand Down
1 change: 1 addition & 0 deletions lib/rspec/mocks/message_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ def call(*args, &block)

proc.call(*args, &block)
end
ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
end

# Represents a configured implementation. Takes into account
Expand Down
12 changes: 12 additions & 0 deletions spec/rspec/mocks/and_invoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ module Mocks
expect(dbl.square_then_cube(2)).to eq 4
expect(dbl.square_then_cube(2)).to eq 8
end

if RSpec::Support::RubyFeatures.kw_args_supported?
binding.eval(<<-RUBY, __FILE__, __LINE__)
it 'passes keyword arguments into the callable' do
expect(dbl).to receive(:square_then_cube).and_invoke(lambda { |i: 1| i ** 2 },
lambda { |i: 1| i ** 3 })

expect(dbl.square_then_cube(i: 2)).to eq 4
expect(dbl.square_then_cube(i: 2)).to eq 8
end
RUBY
end
end
end
end
Expand Down
Loading