diff --git a/rswag-specs/lib/rswag/specs/example_group_helpers.rb b/rswag-specs/lib/rswag/specs/example_group_helpers.rb index ed7b20f..544da6e 100644 --- a/rswag-specs/lib/rswag/specs/example_group_helpers.rb +++ b/rswag-specs/lib/rswag/specs/example_group_helpers.rb @@ -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 diff --git a/rswag-specs/lib/rswag/specs/example_helpers.rb b/rswag-specs/lib/rswag/specs/example_helpers.rb index 1b62bb8..d8ff128 100644 --- a/rswag-specs/lib/rswag/specs/example_helpers.rb +++ b/rswag-specs/lib/rswag/specs/example_helpers.rb @@ -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 diff --git a/rswag-specs/lib/rswag/specs/response_validator.rb b/rswag-specs/lib/rswag/specs/response_validator.rb index f5c4cf7..5b366ce 100644 --- a/rswag-specs/lib/rswag/specs/response_validator.rb +++ b/rswag-specs/lib/rswag/specs/response_validator.rb @@ -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 diff --git a/rswag-specs/spec/rswag/specs/response_validator_spec.rb b/rswag-specs/spec/rswag/specs/response_validator_spec.rb index b93350b..1d05427 100644 --- a/rswag-specs/spec/rswag/specs/response_validator_spec.rb +++ b/rswag-specs/spec/rswag/specs/response_validator_spec.rb @@ -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] = { diff --git a/test-app/spec/integration/blogs_spec.rb b/test-app/spec/integration/blogs_spec.rb index 143dc39..fe7e8c0 100644 --- a/test-app/spec/integration/blogs_spec.rb +++ b/test-app/spec/integration/blogs_spec.rb @@ -22,7 +22,9 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do schema '$ref' => '#/definitions/errors_object' let(:blog) { { title: 'foo' } } - run_test! + run_test! do |response| + expect(response.body).to include("can't be blank") + end end end @@ -37,7 +39,6 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do response '200', 'success' do schema type: 'array', items: { '$ref' => '#/definitions/blog' } - run_test! end response '406', 'unsupported accept header' do diff --git a/test-app/swagger/v1/swagger.json b/test-app/swagger/v1/swagger.json index 27703bf..6489e76 100644 --- a/test-app/swagger/v1/swagger.json +++ b/test-app/swagger/v1/swagger.json @@ -82,15 +82,6 @@ } ], "responses": { - "200": { - "description": "success", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/blog" - } - } - }, "406": { "description": "unsupported accept header" }