Rename response_examples to examples for consistent DSL

Special handling `examples` invocation with no parameters to avoid
overriding the `examples` method of rspec-core ExampleGroup
This commit is contained in:
vinhbachsy
2016-10-19 03:04:03 +08:00
parent 5ea97a4278
commit 0b0acfe4c7
4 changed files with 28 additions and 5 deletions

View File

@@ -61,7 +61,11 @@ module Rswag
metadata[:response][:headers][name] = attributes
end
def response_examples(example)
# NOTE: Similar to 'description', 'examples' need to handle the case when
# being invoked with no params to avoid overriding 'examples' method of
# rspec-core ExampleGroup
def examples(example = nil)
return super() if example.nil?
metadata[:response][:examples] = example
end

View File

@@ -113,7 +113,7 @@ module Rswag
context "'path' parameter" do
before { subject.parameter(name: :id, in: :path) }
let(:api_metadata) { { operation: {} } }
it "automatically sets the 'required' flag" do
expect(api_metadata[:operation][:parameters]).to match(
[ name: :id, in: :path, required: true ]
@@ -151,6 +151,25 @@ module Rswag
)
end
end
describe '#examples(example)' do
let(:json_example) do
{
'application/json' => {
foo: 'bar'
}
}
end
let(:api_metadata) { { response: {} } }
before do
subject.examples(json_example)
end
it "adds to the 'response examples' metadata" do
expect(api_metadata[:response][:examples]).to eq(json_example)
end
end
end
end
end