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

Commit

Permalink
Merge pull request #1595 from rspec/support-kw-args-with-and-invoke
Browse files Browse the repository at this point in the history
Support keyword arguments with and_invoke
  • Loading branch information
JonRowe authored Oct 2, 2024
2 parents 134b1ac + ce49932 commit 56e14be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit 56e14be

Please sign in to comment.