Module: OpenapiFirst::Test::Methods

Defined in:
lib/openapi_first/test/methods.rb

Overview

Methods to use in integration tests

Instance Method Summary collapse

Instance Method Details

#assert_api_conform(status: nil, api: :default) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/openapi_first/test/methods.rb', line 7

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