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

Allow to pass metadata to example_request #497

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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ resource "Account" do
expect(status).to eq 404
end

# With example_request, you can't change the :document
example_request "Get a list on page 3", :page => 3 do
# With example_request, you can change the :document via metadata
example_request "Get a list on page 3", :page => 3, :metadata => {:document => false} do
expect(status).to eq 404
end
end
Expand Down Expand Up @@ -658,6 +658,13 @@ resource "Orders" do
end
```

For passing metadata to example_request you can use param named `:metadata`
```ruby
example_request "Creating an order", :name => "Other name", metadata: {document: :private} do
# make assertions
end
```

#### explanation

This method takes a string representing a detailed explanation of the example.
Expand Down
5 changes: 4 additions & 1 deletion lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ module Endpoint

module ClassMethods
def example_request(description, params = {}, &block)
example description, :caller => block.send(:caller) do
metadata = params.fetch(:metadata, {})
example_params = {caller: block.send(:caller)}.merge!(metadata)

example description, example_params do
do_request(params)
instance_eval &block if block_given?
end
Expand Down