Class: OpenapiFirst::Test::Setup
- Inherits:
-
Object
- Object
- OpenapiFirst::Test::Setup
- Defined in:
- lib/openapi_first/test.rb
Overview
Helper class to setup tests
Instance Attribute Summary collapse
-
#coverage_formatter ⇒ Object
Returns the value of attribute coverage_formatter.
-
#coverage_formatter_options ⇒ Object
Returns the value of attribute coverage_formatter_options.
-
#minimum_coverage ⇒ Object
Returns the value of attribute minimum_coverage.
Instance Method Summary collapse
-
#handle_exit ⇒ Object
This called at_exit.
-
#initialize {|_self| ... } ⇒ Setup
constructor
A new instance of Setup.
- #register(oad, as: :default) ⇒ Object
- #skip_response_coverage(&block) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Setup
Returns a new instance of Setup.
17 18 19 20 21 22 23 |
# File 'lib/openapi_first/test.rb', line 17 def initialize @minimum_coverage = 0 @coverage_formatter = Coverage::TerminalFormatter @coverage_formatter_options = {} @skip_response_coverage = nil yield self end |
Instance Attribute Details
#coverage_formatter ⇒ Object
Returns the value of attribute coverage_formatter.
29 30 31 |
# File 'lib/openapi_first/test.rb', line 29 def coverage_formatter @coverage_formatter end |
#coverage_formatter_options ⇒ Object
Returns the value of attribute coverage_formatter_options.
29 30 31 |
# File 'lib/openapi_first/test.rb', line 29 def @coverage_formatter_options end |
#minimum_coverage ⇒ Object
Returns the value of attribute minimum_coverage.
29 30 31 |
# File 'lib/openapi_first/test.rb', line 29 def minimum_coverage @minimum_coverage end |
Instance Method Details
#handle_exit ⇒ Object
This called at_exit
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/openapi_first/test.rb', line 38 def handle_exit coverage = Coverage.result.coverage # :nocov: puts 'API Coverage did not detect any API requests for the registered API descriptions' if coverage.zero? if coverage.positive? Test.report_coverage( formatter: coverage_formatter, ** ) end return unless minimum_coverage > coverage puts "API Coverage fails with exit 2, because API coverage of #{coverage}% " \ "is below minimum of #{minimum_coverage}%!" exit 2 # :nocov: end |
#register(oad, as: :default) ⇒ Object
25 26 27 |
# File 'lib/openapi_first/test.rb', line 25 def register(oad, as: :default) Test.register(oad, as:) end |
#skip_response_coverage(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/openapi_first/test.rb', line 31 def skip_response_coverage(&block) return @skip_response_coverage unless block_given? @skip_response_coverage = block end |