Skip to content

Commit

Permalink
Declare ruby2_keywords for a method_missing implementation in control…
Browse files Browse the repository at this point in the history
…ler specs
  • Loading branch information
JonRowe committed Aug 13, 2021
1 parent e68175d commit 0f52603
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rspec/rails/example/controller_example_group.rb
Expand Up @@ -176,6 +176,7 @@ def method_missing(method, *args, &block)
super
end
end
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)

included do
subject { controller }
Expand Down
13 changes: 13 additions & 0 deletions spec/rspec/rails/example/controller_example_group_spec.rb
Expand Up @@ -19,6 +19,19 @@ def group_for(klass)
expect(group.included_modules).to include(RSpec::Rails::Matchers::RoutingMatchers)
end

it "handles methods invoked via `method_missing` that use keywords" do
group =
RSpec::Core::ExampleGroup.describe ApplicationController do
def a_method(value:); value; end
def method_missing(_name, *_args, **kwargs, &_block); a_method(**kwargs); end

prepend ControllerExampleGroup
end
example = group.new

expect(example.call_a_method(value: :value)).to eq :value
end

context "with implicit subject" do
it "uses the controller as the subject" do
controller = double('controller')
Expand Down

0 comments on commit 0f52603

Please sign in to comment.