diff --git a/lib/rspec_api_documentation/dsl/endpoint/set_param.rb b/lib/rspec_api_documentation/dsl/endpoint/set_param.rb index 1a52c692..f65dda44 100644 --- a/lib/rspec_api_documentation/dsl/endpoint/set_param.rb +++ b/lib/rspec_api_documentation/dsl/endpoint/set_param.rb @@ -57,7 +57,7 @@ def method_name custom_method_name if example_group.respond_to?(custom_method_name) elsif scoped_key && example_group.respond_to?(scoped_key) scoped_key - elsif key && example_group.respond_to?(key) + elsif key && example_group.respond_to?(key) && example_group.public_method(key).arity.zero? key elsif key && set_value key diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index 46430107..31c5922e 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -54,6 +54,46 @@ end end end + + context "parameter with the same name as HTTP method" do + parameter http_method, "#{http_method} parameter" + + # Simulate ActionDispatch::Integration::RequestHelpers method which + # accepts 1+ arguments. + # + # def get(path, **args) + # process(:get, path, **args) + # end + # + # See https://github.com/rails/rails/blob/v6.1.1/actionpack/lib/action_dispatch/testing/integration.rb#L13-L53 + define_method(http_method) do |_path, **_args| + raise "This method should not have been called" + end + + context "without defining custom method for value" do + example "does not raise error" do + expect(client).to receive(http_method) + + do_request + end + end + + context "with custom method for values defined" do + define_method(http_method) { "value" } + + example "uses custom value" do + expect(client).to receive(http_method) do |*args| + if http_method == :get + expect(args).to eq ["/path?get=value", nil, nil] + else + expect(args).to eq ["/path", { http_method.to_s => "value" }, nil] + end + end + + do_request + end + end + end end end