Class: OpenapiContracts::Match

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  parameters:   false,
  request_body: false
}.freeze
MIN_REQUEST_ANCESTORS =
%w(Rack::Request::Env Rack::Request::Helpers).freeze
MIN_RESPONSE_ANCESTORS =
%w(Rack::Response::Helpers).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, response, options = {}) ⇒ Match

Returns a new instance of Match.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/openapi_contracts/match.rb', line 12

def initialize(doc, response, options = {})
  @doc = doc
  @response = response
  @request = options.delete(:request) { response.request }
  @options = DEFAULT_OPTIONS.merge(options)
  raise ArgumentError, "#{@response} must be compatible with Rack::Response::Helpers" unless response_compatible?
  raise ArgumentError, "#{@request} must be compatible with Rack::Request::{Env,Helpers}" unless request_compatible?
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'lib/openapi_contracts/match.rb', line 10

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/openapi_contracts/match.rb', line 21

def valid?
  return @errors.empty? if instance_variable_defined?(:@errors)

  @errors = matchers.call
  @doc.coverage.increment!(operation.path.to_s, request_method, status, media_type) if collect_coverage?
  @errors.empty?
end