Class: Skooma::Coverage
- Inherits:
-
Object
- Object
- Skooma::Coverage
- Defined in:
- lib/skooma/coverage.rb
Defined Under Namespace
Classes: SimpleReport
Instance Attribute Summary collapse
-
#covered_paths ⇒ Object
Returns the value of attribute covered_paths.
-
#defined_paths ⇒ Object
readonly
Returns the value of attribute defined_paths.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Class Method Summary collapse
Instance Method Summary collapse
- #covered_percent ⇒ Object
-
#initialize(schema, mode:, format:, storage:) ⇒ Coverage
constructor
A new instance of Coverage.
- #report ⇒ Object
- #track_request(result) ⇒ Object
- #uncovered_paths ⇒ Object
Constructor Details
#initialize(schema, mode:, format:, storage:) ⇒ Coverage
Returns a new instance of Coverage.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/skooma/coverage.rb', line 43 def initialize(schema, mode:, format:, storage:) @schema = schema @mode = mode @format = format || SimpleReport @storage = storage || CoverageStore.new stored_data = @storage.load_data @defined_paths = stored_data[:defined_paths] @covered_paths = stored_data[:covered_paths] if @defined_paths.empty? @defined_paths = find_defined_paths(schema) @storage.save_data(@defined_paths, @covered_paths) end end |
Instance Attribute Details
#covered_paths ⇒ Object
Returns the value of attribute covered_paths.
41 42 43 |
# File 'lib/skooma/coverage.rb', line 41 def covered_paths @covered_paths end |
#defined_paths ⇒ Object (readonly)
Returns the value of attribute defined_paths.
40 41 42 |
# File 'lib/skooma/coverage.rb', line 40 def defined_paths @defined_paths end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
40 41 42 |
# File 'lib/skooma/coverage.rb', line 40 def format @format end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
40 41 42 |
# File 'lib/skooma/coverage.rb', line 40 def mode @mode end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
40 41 42 |
# File 'lib/skooma/coverage.rb', line 40 def schema @schema end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
40 41 42 |
# File 'lib/skooma/coverage.rb', line 40 def storage @storage end |
Class Method Details
.new(schema, mode: nil, format: nil, storage: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/skooma/coverage.rb', line 29 def self.new(schema, mode: nil, format: nil, storage: nil) case mode when nil, false NoopCoverage.new when :report, :strict super else raise ArgumentError, "Invalid coverage: #{mode}, expected :report, :strict, or false" end end |
Instance Method Details
#covered_percent ⇒ Object
78 79 80 |
# File 'lib/skooma/coverage.rb', line 78 def covered_percent covered_paths.count * 100.0 / defined_paths.count end |
#report ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/skooma/coverage.rb', line 82 def report stored_data = storage.load_data self.covered_paths = stored_data[:covered_paths] format.new(self).report storage.clear exit 1 if mode == :strict && uncovered_paths.any? end |
#track_request(result) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/skooma/coverage.rb', line 59 def track_request(result) operation = [nil, nil, nil] result.collect_annotations(result.instance, keys: %w[paths responses]) do |node| case node.key when "paths" operation[0] = node.annotation["method"] operation[1] = node.annotation["current_path"] when "responses" operation[2] = node.annotation end end covered_paths << operation storage.save_data(Set.new, Set.new([operation])) end |
#uncovered_paths ⇒ Object
74 75 76 |
# File 'lib/skooma/coverage.rb', line 74 def uncovered_paths defined_paths - covered_paths end |