Response body value validation

Add the possibility to pass a block to the run_test!
method in order to add expectations on your response
This commit is contained in:
Horia Radu
2017-04-28 11:40:33 +03:00
parent cf9170101b
commit 51c9f4e5e6
7 changed files with 44 additions and 11 deletions

View File

@@ -29,7 +29,7 @@ module Rswag
api_metadata[:response][:schema] = {
type: 'object',
properties: { text: { type: 'string' } },
required: [ 'text' ]
required: ['text']
}
end
@@ -42,6 +42,24 @@ module Rswag
let(:response) { OpenStruct.new(code: 200, body: "{\"foo\":\"Some comment\"}") }
it { expect { call }.to raise_error UnexpectedResponse }
end
context "'block' provided" do
let(:call) do
subject.validate!(response) do |body|
expect(body['text']).to eq('Some comment')
end
end
context 'the block validation passes' do
let(:response) { OpenStruct.new(code: 200, body: "{\"text\":\"Some comment\"}") }
it { expect { call }.to_not raise_error }
end
context 'the block validation fails' do
let(:response) { OpenStruct.new(code: 200, body: "{\"text\":\"Some other comment\"}") }
it { expect { call }.to raise_error(RSpec::Expectations::ExpectationNotMetError) }
end
end
end
context "referenced 'schema' provided" do
@@ -51,7 +69,7 @@ module Rswag
author: {
type: 'object',
properties: { name: { type: 'string' } },
required: [ 'name' ]
required: ['name']
}
}
end