Class: OpenapiRspec::RequestValidator

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Includes:
Rack::Test::Methods
Defined in:
lib/openapi_rspec/request_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



21
22
23
# File 'lib/openapi_rspec/request_validator.rb', line 21

def response
  @response
end

#resultObject (readonly)

Returns the value of attribute result.



21
22
23
# File 'lib/openapi_rspec/request_validator.rb', line 21

def result
  @result
end

Instance Method Details

#appObject



23
24
25
# File 'lib/openapi_rspec/request_validator.rb', line 23

def app
  OpenapiRspec.app
end

#descriptionObject



36
37
38
# File 'lib/openapi_rspec/request_validator.rb', line 36

def description
  "return valid response with code #{code} on `#{method.to_s.upcase} #{path}`"
end

#failure_messageObject



40
41
42
43
44
45
46
# File 'lib/openapi_rspec/request_validator.rb', line 40

def failure_message
  if response
    (%W[Response: #{response.body}] + result.errors).join("\n")
  else
    result.errors.join("\n")
  end
end

#matches?(doc) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/openapi_rspec/request_validator.rb', line 27

def matches?(doc)
  @result = doc.validate_request(path: path, method: method, code: code, media_type: media_type)
  return false unless result.valid?

  perform_request(doc)
  result.validate_response(body: response.body, code: response.status)
  result.valid?
end