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

Commit 3829d7a

Browse files
committed
Support keyword arguments with and_invoke
1 parent 134b1ac commit 3829d7a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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)