yield entire response instead of only the body

This commit is contained in:
Horia Radu 2017-04-29 21:17:53 +03:00
parent 37f86f6d94
commit f195c82759
3 changed files with 5 additions and 6 deletions

View File

@ -108,7 +108,7 @@ If you want to do additional validation on the response, pass a block to the __r
```ruby
response '201', 'blog created' do
run_test! do |response|
data = JSON.parse(response)
data = JSON.parse(response.body)
expect(data['title']).to eq('foo')
end
end

View File

@ -16,6 +16,7 @@ module Rswag
validate_code!(response.code)
validate_headers!(response.headers)
validate_body!(response.body, &block)
block.call(response) if block_given?
end
private
@ -35,7 +36,7 @@ module Rswag
end
end
def validate_body!(body, &block)
def validate_body!(body)
response_schema = @api_metadata[:response][:schema]
return if response_schema.nil?
@ -47,8 +48,6 @@ module Rswag
rescue JSON::Schema::ValidationError => ex
raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}"
end
block.call(body) if block_given?
end
end

View File

@ -45,8 +45,8 @@ module Rswag
context "'block' provided" do
let(:call) do
subject.validate!(response) do |body|
data = JSON.parse(body)
subject.validate!(response) do |response|
data = JSON.parse(response.body)
expect(data['text']).to eq('Some comment')
end
end