Class: OpenapiRuby::Testing::Coverage
- Inherits:
-
Object
- Object
- OpenapiRuby::Testing::Coverage
- Defined in:
- lib/openapi_ruby/testing/coverage.rb
Instance Attribute Summary collapse
-
#covered ⇒ Object
readonly
Returns the value of attribute covered.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(document) ⇒ Coverage
constructor
A new instance of Coverage.
- #percentage ⇒ Object
- #record(method, path, status_code) ⇒ Object
- #report ⇒ Object
- #to_json(*_args) ⇒ Object
- #uncovered ⇒ Object
Constructor Details
#initialize(document) ⇒ Coverage
Returns a new instance of Coverage.
8 9 10 11 12 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 8 def initialize(document) @document = document @covered = Set.new @total = extract_all_endpoints end |
Instance Attribute Details
#covered ⇒ Object (readonly)
Returns the value of attribute covered.
6 7 8 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 6 def covered @covered end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
6 7 8 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 6 def total @total end |
Instance Method Details
#percentage ⇒ Object
23 24 25 26 27 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 23 def percentage return 100.0 if @total.empty? (@covered.size.to_f / @total.size * 100).round(1) end |
#record(method, path, status_code) ⇒ Object
14 15 16 17 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 14 def record(method, path, status_code) key = "#{method.upcase} #{path} #{status_code}" @covered.add(key) end |
#report ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 29 def report { total: @total.size, covered: @covered.size, uncovered: uncovered.size, percentage: percentage, missing: uncovered.to_a.sort } end |
#to_json(*_args) ⇒ Object
39 40 41 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 39 def to_json(*_args) JSON.pretty_generate(report) end |
#uncovered ⇒ Object
19 20 21 |
# File 'lib/openapi_ruby/testing/coverage.rb', line 19 def uncovered @total - @covered end |