mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
simplify validation blocks and use correct scope
This commit is contained in:
@@ -77,7 +77,8 @@ module Rswag
|
||||
end
|
||||
|
||||
it "returns a #{metadata[:response][:code]} response" do
|
||||
assert_response_matches_metadata(example.metadata, &block)
|
||||
assert_response_matches_metadata(metadata)
|
||||
block.call(response) if block_given?
|
||||
end
|
||||
else
|
||||
before do |example|
|
||||
@@ -86,6 +87,7 @@ module Rswag
|
||||
|
||||
it "returns a #{metadata[:response][:code]} response" do |example|
|
||||
assert_response_matches_metadata(example.metadata, &block)
|
||||
example.instance_exec(response, &block) if block_given?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,8 +27,8 @@ module Rswag
|
||||
end
|
||||
end
|
||||
|
||||
def assert_response_matches_metadata(metadata, &block)
|
||||
ResponseValidator.new.validate!(metadata, response, &block)
|
||||
def assert_response_matches_metadata(metadata)
|
||||
ResponseValidator.new.validate!(metadata, response)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,13 +11,12 @@ module Rswag
|
||||
@config = config
|
||||
end
|
||||
|
||||
def validate!(metadata, response, &block)
|
||||
def validate!(metadata, response)
|
||||
swagger_doc = @config.get_swagger_doc(metadata[:swagger_doc])
|
||||
|
||||
validate_code!(metadata, response.code)
|
||||
validate_headers!(metadata, response.headers)
|
||||
validate_body!(metadata, swagger_doc, response.body, &block)
|
||||
block.call(response) if block_given?
|
||||
validate_body!(metadata, swagger_doc, response.body)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -55,20 +55,6 @@ module Rswag
|
||||
it { expect { call }.to raise_error /Expected response body/ }
|
||||
end
|
||||
|
||||
context 'validation block provided' do
|
||||
let(:call) { subject.validate!(metadata, response, &block) }
|
||||
|
||||
context 'block passes' do
|
||||
let(:block) { Proc.new { |response| expect(response.code).to eq('200') } }
|
||||
it { expect { call }.to_not raise_error }
|
||||
end
|
||||
|
||||
context 'block fails' do
|
||||
let(:block) { Proc.new { |response| expect(response.code).to eq('201') } }
|
||||
it { expect { call }.to raise_error RSpec::Expectations::ExpectationNotMetError }
|
||||
end
|
||||
end
|
||||
|
||||
context 'referenced schemas' do
|
||||
before do
|
||||
swagger_doc[:definitions] = {
|
||||
|
||||
Reference in New Issue
Block a user