Class: OpenapiFirst::Test::Setup

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

Overview

Helper class to setup tests

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Setup

Returns a new instance of Setup.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
# File 'lib/openapi_first/test.rb', line 17

def initialize
  @minimum_coverage = 0
  yield self
end

Instance Attribute Details

#minimum_coverageObject

Returns the value of attribute minimum_coverage.



26
27
28
# File 'lib/openapi_first/test.rb', line 26

def minimum_coverage
  @minimum_coverage
end

Instance Method Details

#handle_exitObject

This called at_exit



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openapi_first/test.rb', line 29

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?
  Test.report_coverage if coverage.positive?
  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

#registerObject



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

def register(*)
  Test.register(*)
end