From 582baa84fd59ad9f234060868043da8ec8716002 Mon Sep 17 00:00:00 2001 From: Semyon Pupkov Date: Fri, 23 Jul 2021 17:39:50 +0500 Subject: [PATCH] Allow to pass metadata to example_request --- README.md | 11 +++++++++-- lib/rspec_api_documentation/dsl/endpoint.rb | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3a02de80..ce75217f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 1b221914..67741fff 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -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