simplify validation blocks and use correct scope

This commit is contained in:
domaindrivendev
2017-07-21 22:26:14 -07:00
parent 7f0e437f8b
commit 732cab994c
6 changed files with 10 additions and 31 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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