Module: SimpleCov::CoverageViolations
- Defined in:
- lib/simplecov/coverage_violations.rb
Overview
Computes coverage threshold violations for a given result. Shared by the exit-code checks and the JSON formatter’s ‘errors` section.
Each method returns an array of violation hashes. All percents are rounded via ‘SimpleCov.round_coverage` so downstream consumers don’t need to round again.
Class Method Summary collapse
-
.maximum_drop(result, thresholds, last_run: SimpleCov::LastRun.read) ⇒ Array<Hash>
:maximum, :actual where ‘actual` is the observed drop (in percentage points) vs.
-
.maximum_overall(result, thresholds) ⇒ Array<Hash>
Tolerance: ‘percent_for` floors the actual percent to two decimal places (matching the existing minimum-coverage behavior), so an actual of e.g.
-
.minimum_by_file(result, defaults, overrides = {}) ⇒ Array<Hash>
‘defaults` is the criterion-keyed Hash applied to every file.
-
.minimum_by_group(result, thresholds) ⇒ Array<Hash>
:criterion, :expected, :actual.
-
.minimum_overall(result, thresholds) ⇒ Array<Hash>
:expected, :actual.
Class Method Details
.maximum_drop(result, thresholds, last_run: SimpleCov::LastRun.read) ⇒ Array<Hash>
Returns :maximum, :actual where ‘actual` is the observed drop (in percentage points) vs. the last run.
55 56 57 58 59 60 61 62 |
# File 'lib/simplecov/coverage_violations.rb', line 55 def maximum_drop(result, thresholds, last_run: SimpleCov::LastRun.read) return [] unless last_run thresholds.filter_map do |criterion, maximum| actual = compute_drop(criterion, result, last_run) {criterion: criterion, maximum: maximum, actual: actual} if actual && actual > maximum end end |
.maximum_overall(result, thresholds) ⇒ Array<Hash>
Tolerance: ‘percent_for` floors the actual percent to two decimal places (matching the existing minimum-coverage behavior), so an actual of e.g. 95.4287 is treated as 95.42 — meaning a maximum of 95.42 still passes. See issue #187 for the rationale.
25 26 27 28 29 30 |
# File 'lib/simplecov/coverage_violations.rb', line 25 def maximum_overall(result, thresholds) thresholds.filter_map do |criterion, expected| actual = percent_for(result, criterion) or next {criterion: criterion, expected: expected, actual: actual} if actual > expected end end |
.minimum_by_file(result, defaults, overrides = {}) ⇒ Array<Hash>
‘defaults` is the criterion-keyed Hash applied to every file. `overrides` is an ordered Hash<pattern, criterion_thresholds> of per-path overrides; for each file, defaults are merged with every matching override (later wins per criterion, overrides win over defaults).
38 39 40 41 42 43 |
# File 'lib/simplecov/coverage_violations.rb', line 38 def minimum_by_file(result, defaults, overrides = {}) result.files.flat_map do |file| effective = effective_per_file_thresholds(file, defaults, overrides) effective.filter_map { |criterion, expected| file_minimum_violation(file, criterion, expected) } end end |
.minimum_by_group(result, thresholds) ⇒ Array<Hash>
Returns :criterion, :expected, :actual.
46 47 48 49 50 51 |
# File 'lib/simplecov/coverage_violations.rb', line 46 def minimum_by_group(result, thresholds) thresholds.flat_map do |group_name, minimums| group = lookup_group(result, group_name) group ? group_minimum_violations(group_name, group, minimums) : [] end end |
.minimum_overall(result, thresholds) ⇒ Array<Hash>
Returns :expected, :actual.
13 14 15 16 17 18 |
# File 'lib/simplecov/coverage_violations.rb', line 13 def minimum_overall(result, thresholds) thresholds.filter_map do |criterion, expected| actual = percent_for(result, criterion) or next {criterion: criterion, expected: expected, actual: actual} if actual < expected end end |