Class: RSpec::FlakeClassifier::CoverageSnapshot
- Inherits:
-
Object
- Object
- RSpec::FlakeClassifier::CoverageSnapshot
- Defined in:
- lib/rspec/flake/classifier/coverage_snapshot.rb,
sig/rspec/flake/classifier.rbs
Class Method Summary collapse
- .capture ⇒ CoverageSnapshot
- .capture_snapshot ⇒ Object
- .line_counts(value) ⇒ Object
- .normalize_static(data) ⇒ Object
- .null ⇒ CoverageSnapshot
Instance Method Summary collapse
- #delta ⇒ Hash[String, Array[Integer]]
-
#initialize(data) ⇒ CoverageSnapshot
constructor
A new instance of CoverageSnapshot.
Constructor Details
#initialize(data) ⇒ CoverageSnapshot
Returns a new instance of CoverageSnapshot.
21 22 23 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 21 def initialize(data) @data = normalize(data) end |
Class Method Details
.capture ⇒ CoverageSnapshot
8 9 10 11 12 13 14 15 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 8 def self.capture return null unless Coverage.respond_to?(:running?) && Coverage.running? return null unless Coverage.respond_to?(:peek_result) new(Coverage.peek_result) rescue RuntimeError null end |
.capture_snapshot ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 33 def self.capture_snapshot return {} unless Coverage.respond_to?(:running?) && Coverage.running? return {} unless Coverage.respond_to?(:peek_result) normalize_static(Coverage.peek_result) rescue RuntimeError {} end |
.line_counts(value) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 48 def self.line_counts(value) return Array(value) if value.is_a?(Array) return Array(value[:lines]) if value.is_a?(Hash) && value.key?(:lines) return Array(value["lines"]) if value.is_a?(Hash) && value.key?("lines") [] end |
.normalize_static(data) ⇒ Object
42 43 44 45 46 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 42 def self.normalize_static(data) data.each_with_object({}) do |(file, value), result| result[file.to_s] = line_counts(value) end end |
.null ⇒ CoverageSnapshot
17 18 19 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 17 def self.null new({}) end |
Instance Method Details
#delta ⇒ Hash[String, Array[Integer]]
25 26 27 28 29 30 31 |
# File 'lib/rspec/flake/classifier/coverage_snapshot.rb', line 25 def delta after = self.class.capture_snapshot after.each_with_object({}) do |(file, counts), result| changed = line_delta(Array(@data[file]), counts) result[relative_path(file)] = changed unless changed.empty? end end |