Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call value method if it has zero arity #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec_api_documentation/dsl/endpoint/set_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down