Class: OpenapiFirst::Test::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/test/configuration.rb

Overview

Helper class to setup tests

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  @minimum_coverage = 100
  @coverage_formatter = Coverage::TerminalFormatter
  @coverage_formatter_options = {}
  @skip_response_coverage = nil
  @skip_coverage = nil
  @response_raise_error = true
  @ignored_unknown_status = Set.new([401, 404, 500])
  @ignore_unknown_response_status = false
  @report_coverage = true
  @ignore_unknown_requests = false
end

Instance Attribute Details

#coverage_formatterObject

Returns the value of attribute coverage_formatter.



32
33
34
# File 'lib/openapi_first/test/configuration.rb', line 32

def coverage_formatter
  @coverage_formatter
end

#coverage_formatter_optionsObject

Returns the value of attribute coverage_formatter_options.



32
33
34
# File 'lib/openapi_first/test/configuration.rb', line 32

def coverage_formatter_options
  @coverage_formatter_options
end

#ignore_unknown_requestsObject

Returns the value of attribute ignore_unknown_requests.



32
33
34
# File 'lib/openapi_first/test/configuration.rb', line 32

def ignore_unknown_requests
  @ignore_unknown_requests
end

#ignore_unknown_response_statusObject Also known as: ignore_unknown_response_status?

Returns the value of attribute ignore_unknown_response_status.



32
33
34
# File 'lib/openapi_first/test/configuration.rb', line 32

def ignore_unknown_response_status
  @ignore_unknown_response_status
end

#ignored_unknown_statusObject

Returns the value of attribute ignored_unknown_status.



34
35
36
# File 'lib/openapi_first/test/configuration.rb', line 34

def ignored_unknown_status
  @ignored_unknown_status
end

#minimum_coverageObject

Returns the value of attribute minimum_coverage.



32
33
34
# File 'lib/openapi_first/test/configuration.rb', line 32

def minimum_coverage
  @minimum_coverage
end

#report_coverageObject

Returns the value of attribute report_coverage.



34
35
36
# File 'lib/openapi_first/test/configuration.rb', line 34

def report_coverage
  @report_coverage
end

#response_raise_errorObject

Returns the value of attribute response_raise_error.



32
33
34
# File 'lib/openapi_first/test/configuration.rb', line 32

def response_raise_error
  @response_raise_error
end

Instance Method Details

#ignore_response?(validated_response) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
# File 'lib/openapi_first/test/configuration.rb', line 67

def ignore_response?(validated_response)
  return false if validated_response.known?

  return true if ignored_unknown_status.include?(validated_response.status)

  ignore_unknown_response_status? && validated_response.error.type == :response_status_not_found
end

#observe(app, api: :default) ⇒ Object

Observe a rack app



28
29
30
# File 'lib/openapi_first/test/configuration.rb', line 28

def observe(app, api: :default)
  Observe.observe(app, api:)
end

#register(oad, as: :default) ⇒ Object

Register OADs, but don’t load them just yet

Parameters:

  • oad (OpenapiFirst::OAD)

    The OAD to register

  • as (Symbol) (defaults to: :default)

    The name to register the OAD under



23
24
25
# File 'lib/openapi_first/test/configuration.rb', line 23

def register(oad, as: :default)
  Test.register(oad, as:)
end

#skip_coverage(&block) ⇒ Object



59
60
61
62
63
# File 'lib/openapi_first/test/configuration.rb', line 59

def skip_coverage(&block)
  return @skip_coverage unless block_given?

  @skip_coverage = block
end

#skip_response_coverage(&block) ⇒ Object



53
54
55
56
57
# File 'lib/openapi_first/test/configuration.rb', line 53

def skip_response_coverage(&block)
  return @skip_response_coverage unless block_given?

  @skip_response_coverage = block
end