diff --git a/README.md b/README.md index 28e18b6..8d4355c 100644 --- a/README.md +++ b/README.md @@ -103,12 +103,13 @@ If you've used [Swagger](http://swagger.io/specification) before, then the synta Take special note of the __run_test!__ method that's called within each response block. This tells rswag to create and execute a corresponding example. It builds and submits a request based on parameter descriptions and corresponding values that have been provided using the rspec "let" syntax. For example, the "post" description in the example above specifies a "body" parameter called "blog". It also lists 2 different responses. For the success case (i.e. the 201 response), notice how "let" is used to set the blog parameter to a value that matches the provided schema. For the failure case (i.e. the 422 response), notice how it's set to a value that does not match the provided schema. When the test is executed, rswag also validates the actual response code and, where applicable, the response body against the provided [JSON Schema](http://json-schema.org/documentation.html). -If you want to do additional validation on the JSON response, pass a block to the __run_test!__ method: +If you want to do additional validation on the response, pass a block to the __run_test!__ method: ```ruby response '201', 'blog created' do - run_test! do |body| - expect(body['title']).to eq('foo') + run_test! do |response| + data = JSON.parse(response) + expect(data['title']).to eq('foo') end end ``` diff --git a/rswag-specs/lib/rswag/specs/response_validator.rb b/rswag-specs/lib/rswag/specs/response_validator.rb index 946c53d..2e75097 100644 --- a/rswag-specs/lib/rswag/specs/response_validator.rb +++ b/rswag-specs/lib/rswag/specs/response_validator.rb @@ -48,7 +48,7 @@ module Rswag raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}" end - block.call(JSON.parse(body)) if block_given? + block.call(body) if block_given? end end diff --git a/rswag-specs/spec/rswag/specs/response_validator_spec.rb b/rswag-specs/spec/rswag/specs/response_validator_spec.rb index 02316c7..bf1bba6 100644 --- a/rswag-specs/spec/rswag/specs/response_validator_spec.rb +++ b/rswag-specs/spec/rswag/specs/response_validator_spec.rb @@ -46,7 +46,8 @@ module Rswag context "'block' provided" do let(:call) do subject.validate!(response) do |body| - expect(body['text']).to eq('Some comment') + data = JSON.parse(body) + expect(data['text']).to eq('Some comment') end end