Skip to content

Commit 0a7f993

Browse files
committed
Declare ruby2_keywords for a method_missing implementation in controller specs
1 parent e68175d commit 0a7f993

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/rspec/rails/example/controller_example_group.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def method_missing(method, *args, &block)
176176
super
177177
end
178178
end
179+
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
179180

180181
included do
181182
subject { controller }

spec/rspec/rails/example/controller_example_group_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ def group_for(klass)
1919
expect(group.included_modules).to include(RSpec::Rails::Matchers::RoutingMatchers)
2020
end
2121

22+
it "handles methods invoked via `method_missing` that use keywords" do
23+
group =
24+
RSpec::Core::ExampleGroup.describe ApplicationController do
25+
def a_method(value:); value; end
26+
def method_missing(_name, *args, **kwargs, &block); a_method(**kwargs); end
27+
28+
prepend ControllerExampleGroup
29+
end
30+
example = group.new
31+
32+
expect(example.call_a_method(value: :value)).to eq :value
33+
end
34+
2235
context "with implicit subject" do
2336
it "uses the controller as the subject" do
2437
controller = double('controller')

0 commit comments

Comments
 (0)