-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix warning about missing assertions when using assert_api_conform in…
… Minitest
- Loading branch information
Showing
5 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenapiFirst | ||
module Test | ||
# Assertion methods for Minitest | ||
module MinitestHelpers | ||
def assert_api_conform(status: nil, api: :default) | ||
api = OpenapiFirst::Test[api] | ||
request = respond_to?(:last_request) ? last_request : @request | ||
response = respond_to?(:last_response) ? last_response : @response | ||
|
||
if status | ||
assert_equal status, response.status, | ||
"Expected status #{status}, but got #{response.status} " \ | ||
"from #{request.request_method.upcase} #{request.path}." | ||
end | ||
|
||
validated_request = api.validate_request(request, raise_error: false) | ||
validated_response = api.validate_response(request, response, raise_error: false) | ||
|
||
assert validated_request.valid?, validated_request.error&.exception_message | ||
assert validated_response.valid?, validated_response.error&.exception_message | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenapiFirst | ||
module Test | ||
# Assertion methods to use when no known test framework was found | ||
# These methods just raise an exception if an error was found | ||
module PlainHelpers | ||
def assert_api_conform(status: nil, api: :default) | ||
api = OpenapiFirst::Test[api] | ||
request = respond_to?(:last_request) ? last_request : @request | ||
response = respond_to?(:last_response) ? last_response : @response | ||
|
||
if status && status != response.status | ||
raise OpenapiFirst::Error, | ||
"Expected status #{status}, but got #{response.status} " \ | ||
"from #{request.request_method.upcase} #{request.path}." | ||
end | ||
|
||
api.validate_request(request, raise_error: true) | ||
api.validate_response(request, response, raise_error: true) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters