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

Commit 56e14be

Browse files
authored
Merge pull request #1595 from rspec/support-kw-args-with-and-invoke
Support keyword arguments with and_invoke
2 parents 134b1ac + ce49932 commit 56e14be

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
### Development
22
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.13.1...main)
33

4+
Bug Fixes:
5+
6+
* Support keyword arguments in callables passed to `and_invoke`. (Jon Rowe, #1595)
7+
48
### 3.13.1 / 2024-05-08
59
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.13.0...v3.13.1)
610

lib/rspec/mocks/message_expectation.rb

+1
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ def call(*args, &block)
748748

749749
proc.call(*args, &block)
750750
end
751+
ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
751752
end
752753

753754
# Represents a configured implementation. Takes into account

spec/rspec/mocks/and_invoke_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ module Mocks
3939
expect(dbl.square_then_cube(2)).to eq 4
4040
expect(dbl.square_then_cube(2)).to eq 8
4141
end
42+
43+
if RSpec::Support::RubyFeatures.kw_args_supported?
44+
binding.eval(<<-RUBY, __FILE__, __LINE__)
45+
it 'passes keyword arguments into the callable' do
46+
expect(dbl).to receive(:square_then_cube).and_invoke(lambda { |i: 1| i ** 2 },
47+
lambda { |i: 1| i ** 3 })
48+
49+
expect(dbl.square_then_cube(i: 2)).to eq 4
50+
expect(dbl.square_then_cube(i: 2)).to eq 8
51+
end
52+
RUBY
53+
end
4254
end
4355
end
4456
end

0 commit comments

Comments
 (0)