Skip to content

Commit

Permalink
Support keyword arguments with and_invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Oct 1, 2024
1 parent 134b1ac commit 08d5c77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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:| i ** 2 },
lambda { |i:| 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 08d5c77

Please sign in to comment.