Class: OpenapiFirst::Test::Configuration
- Inherits:
-
Object
- Object
- OpenapiFirst::Test::Configuration
- Defined in:
- lib/openapi_first/test/configuration.rb
Overview
Helper class to setup tests
Instance Attribute Summary collapse
-
#coverage_reporter ⇒ Object
Returns the value of attribute coverage_reporter.
-
#coverage_reporter_options ⇒ Object
Returns the value of attribute coverage_reporter_options.
-
#ignore_unknown_requests ⇒ Object
(also: #ignore_unknown_requests?)
Returns the value of attribute ignore_unknown_requests.
-
#ignore_unknown_response_status ⇒ Object
(also: #ignore_unknown_response_status?)
Returns the value of attribute ignore_unknown_response_status.
-
#ignored_unknown_status ⇒ Object
Returns the value of attribute ignored_unknown_status.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#minimum_coverage ⇒ Object
Returns the value of attribute minimum_coverage.
-
#report_coverage ⇒ Object
Returns the value of attribute report_coverage.
-
#response_raise_error ⇒ Object
Returns the value of attribute response_raise_error.
Instance Method Summary collapse
-
#coverage_formatter ⇒ Object
deprecated
Deprecated.
Use #coverage_reporter instead.
-
#coverage_formatter=(value) ⇒ Object
deprecated
Deprecated.
Use #coverage_reporter= instead.
-
#coverage_formatter_options ⇒ Object
deprecated
Deprecated.
Use #coverage_reporter_options instead.
-
#coverage_formatter_options=(value) ⇒ Object
deprecated
Deprecated.
Use #coverage_reporter_options= instead.
-
#ignore_request_error(&block) ⇒ Object
Ignore certain errors for certain requests.
-
#ignore_response_error(&block) ⇒ Object
Ignore certain errors for certain responses.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#observe(app, api: :default) ⇒ Object
Observe a rack app.
- #raise_request_error?(validated_request) ⇒ Boolean
- #raise_response_error?(validated_response, rack_request) ⇒ Boolean
-
#register(oad, as: :default) ⇒ Object
Register OADs, but don’t load them just yet.
- #skip_coverage(&block) ⇒ Object
- #skip_response_coverage(&block) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/openapi_first/test/configuration.rb', line 9 def initialize @minimum_coverage = 100 @coverage_reporter = Coverage::HtmlReporter @coverage_reporter_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 @ignore_request_error = nil @ignore_response_error = nil @logger = Logger.new($stdout) end |
Instance Attribute Details
#coverage_reporter ⇒ Object
Returns the value of attribute coverage_reporter.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def coverage_reporter @coverage_reporter end |
#coverage_reporter_options ⇒ Object
Returns the value of attribute coverage_reporter_options.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def @coverage_reporter_options end |
#ignore_unknown_requests ⇒ Object Also known as: ignore_unknown_requests?
Returns the value of attribute ignore_unknown_requests.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def ignore_unknown_requests @ignore_unknown_requests end |
#ignore_unknown_response_status ⇒ Object Also known as: ignore_unknown_response_status?
Returns the value of attribute ignore_unknown_response_status.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def ignore_unknown_response_status @ignore_unknown_response_status end |
#ignored_unknown_status ⇒ Object
Returns the value of attribute ignored_unknown_status.
39 40 41 |
# File 'lib/openapi_first/test/configuration.rb', line 39 def ignored_unknown_status @ignored_unknown_status end |
#logger ⇒ Object
Returns the value of attribute logger.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def logger @logger end |
#minimum_coverage ⇒ Object
Returns the value of attribute minimum_coverage.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def minimum_coverage @minimum_coverage end |
#report_coverage ⇒ Object
Returns the value of attribute report_coverage.
39 40 41 |
# File 'lib/openapi_first/test/configuration.rb', line 39 def report_coverage @report_coverage end |
#response_raise_error ⇒ Object
Returns the value of attribute response_raise_error.
37 38 39 |
# File 'lib/openapi_first/test/configuration.rb', line 37 def response_raise_error @response_raise_error end |
Instance Method Details
#coverage_formatter ⇒ Object
Use #coverage_reporter instead.
42 43 44 45 |
# File 'lib/openapi_first/test/configuration.rb', line 42 def coverage_formatter warn_coverage_formatter_deprecation coverage_reporter end |
#coverage_formatter=(value) ⇒ Object
Use #coverage_reporter= instead.
48 49 50 51 |
# File 'lib/openapi_first/test/configuration.rb', line 48 def coverage_formatter=(value) warn_coverage_formatter_deprecation self.coverage_reporter = value end |
#coverage_formatter_options ⇒ Object
Use #coverage_reporter_options instead.
54 55 56 57 |
# File 'lib/openapi_first/test/configuration.rb', line 54 def warn_coverage_formatter_deprecation end |
#coverage_formatter_options=(value) ⇒ Object
Use #coverage_reporter_options= instead.
60 61 62 63 |
# File 'lib/openapi_first/test/configuration.rb', line 60 def (value) warn_coverage_formatter_deprecation self. = value end |
#ignore_request_error(&block) ⇒ Object
Ignore certain errors for certain requests
84 85 86 87 88 89 90 |
# File 'lib/openapi_first/test/configuration.rb', line 84 def ignore_request_error(&block) # :nocov: raise ArgumentError, 'You have to pass a block' unless block_given? # :nocov: @ignore_request_error = block end |
#ignore_response_error(&block) ⇒ Object
Ignore certain errors for certain responses
94 95 96 97 98 99 100 |
# File 'lib/openapi_first/test/configuration.rb', line 94 def ignore_response_error(&block) # :nocov: raise ArgumentError, 'You have to pass a block' unless block_given? # :nocov: @ignore_response_error = block end |
#observe(app, api: :default) ⇒ Object
Observe a rack app
33 34 35 |
# File 'lib/openapi_first/test/configuration.rb', line 33 def observe(app, api: :default) Observe.observe(app, api:) end |
#raise_request_error?(validated_request) ⇒ Boolean
118 119 120 121 122 123 |
# File 'lib/openapi_first/test/configuration.rb', line 118 def raise_request_error?(validated_request) return false if @ignore_request_error&.call(validated_request) return false if ignore_unknown_requests? && validated_request.unknown? true end |
#raise_response_error?(validated_response, rack_request) ⇒ Boolean
125 126 127 128 129 130 131 132 |
# File 'lib/openapi_first/test/configuration.rb', line 125 def raise_response_error?(validated_response, rack_request) return false if @ignore_response_error&.call(validated_response, rack_request) return false if response_raise_error == false return false if ignored_unknown_status.include?(validated_response.status) return false if ignore_unknown_response_status? && validated_response.error.type == :response_status_not_found true end |
#register(oad, as: :default) ⇒ Object
Register OADs, but don’t load them just yet
28 29 30 |
# File 'lib/openapi_first/test/configuration.rb', line 28 def register(oad, as: :default) Test.register(oad, as:) end |
#skip_coverage(&block) ⇒ Object
109 110 111 112 113 |
# File 'lib/openapi_first/test/configuration.rb', line 109 def skip_coverage(&block) return @skip_coverage unless block_given? @skip_coverage = block end |
#skip_response_coverage(&block) ⇒ Object
103 104 105 106 107 |
# File 'lib/openapi_first/test/configuration.rb', line 103 def skip_response_coverage(&block) return @skip_response_coverage unless block_given? @skip_response_coverage = block end |