Class: OpenapiContracts::Matchers::MatchOpenapiDoc
- Inherits:
-
Object
- Object
- OpenapiContracts::Matchers::MatchOpenapiDoc
- Defined in:
- lib/openapi_contracts/matchers/match_openapi_doc.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(doc) ⇒ MatchOpenapiDoc
constructor
A new instance of MatchOpenapiDoc.
- #matches?(response) ⇒ Boolean
- #with_http_status(status) ⇒ Object
Constructor Details
#initialize(doc) ⇒ MatchOpenapiDoc
Returns a new instance of MatchOpenapiDoc.
4 5 6 7 |
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 4 def initialize(doc) @doc = doc @errors = [] end |
Instance Method Details
#description ⇒ Object
24 25 26 27 28 |
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 24 def description desc = 'to match the openapi schema' desc << " with #{http_status_desc(@status)}" if @status desc end |
#failure_message ⇒ Object
30 31 32 |
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 30 def @errors.map { |e| "* #{e}" }.join("\n") end |
#failure_message_when_negated ⇒ Object
34 35 36 |
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 34 def 'request matched the schema' end |
#matches?(response) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 18 def matches?(response) @response = response response_documented? && http_status_matches? && [headers_match?, body_matches?].all? @errors.empty? end |
#with_http_status(status) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 9 def with_http_status(status) if status.is_a? Symbol @status = Rack::Utils::SYMBOL_TO_STATUS_CODE[status] else @status = status end self end |