Class: OpenapiContracts::Matchers::MatchOpenapiDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/matchers/match_openapi_doc.rb

Instance Method Summary collapse

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

#descriptionObject



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_messageObject



30
31
32
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 30

def failure_message
  @errors.map { |e| "* #{e}" }.join("\n")
end

#failure_message_when_negatedObject



34
35
36
# File 'lib/openapi_contracts/matchers/match_openapi_doc.rb', line 34

def failure_message_when_negated
  'request matched the schema'
end

#matches?(response) ⇒ Boolean

Returns:

  • (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