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

Commit 117b33d

Browse files
authored
Merge pull request #1385 from bryanp/fix-kwargs-for-ruby3
Resolve an issue using method doubles with keyword arguments on Ruby 3
2 parents 6ab343c + 2ca170b commit 117b33d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/rspec/mocks/method_double.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def define_proxy_method
6363
define_method(method_name) do |*args, &block|
6464
method_double.proxy_method_invoked(self, *args, &block)
6565
end
66+
ruby2_keywords(method_name) if Module.private_method_defined?(:ruby2_keywords)
6667
__send__(visibility, method_name)
6768
end
6869

spec/rspec/mocks/and_call_original_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ class << self
185185
expect(klazz.alternate_new).to be_an_instance_of(klazz)
186186
end
187187

188+
if RSpec::Support::RubyFeatures.kw_args_supported?
189+
binding.eval(<<-CODE, __FILE__, __LINE__)
190+
it "works for methods that accept keyword arguments" do
191+
def instance.foo(bar: nil); bar; end
192+
expect(instance).to receive(:foo).and_call_original
193+
expect(instance.foo(bar: "baz")).to eq("baz")
194+
end
195+
CODE
196+
end
197+
188198
context 'on an object that defines method_missing' do
189199
before do
190200
klass.class_exec do

0 commit comments

Comments
 (0)