Module: SimpleCov::CoverageViolations
| Relationships & Source Files | |
| 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 round_coverage so downstream consumers don't need to round again.
Class Method Summary
- .maximum_drop(result, thresholds, last_run: SimpleCov::LastRun.read) ⇒ Array<Hash>
- .minimum_by_file(result, thresholds) ⇒ Array<Hash>
- .minimum_by_group(result, thresholds) ⇒ Array<Hash>
- .minimum_overall(result, thresholds) ⇒ Array<Hash>
- .compute_drop(criterion, result, last_run) private
- .file_minimum_violation(file, criterion, expected) private
- .group_minimum_violations(group_name, group, minimums) private
- .lookup_group(result, group_name) private
- .round(percent) private
Class Method Details
.compute_drop(criterion, result, last_run) (private)
[ GitHub ]# File 'lib/simplecov/coverage_violations.rb', line 74
def compute_drop(criterion, result, last_run) last_coverage_percent = last_run.dig(:result, criterion) last_coverage_percent ||= last_run.dig(:result, :covered_percent) if criterion == :line return unless last_coverage_percent current = round(result.coverage_statistics.fetch(criterion).percent) (last_coverage_percent - current).floor(10) end
.file_minimum_violation(file, criterion, expected) (private)
[ GitHub ]# File 'lib/simplecov/coverage_violations.rb', line 48
def file_minimum_violation(file, criterion, expected) actual = round(file.coverage_statistics.fetch(criterion).percent) return unless actual < expected { criterion: criterion, expected: expected, actual: actual, filename: file.filename, project_filename: file.project_filename } end
.group_minimum_violations(group_name, group, minimums) (private)
[ GitHub ]# File 'lib/simplecov/coverage_violations.rb', line 61
def group_minimum_violations(group_name, group, minimums) minimums.filter_map do |criterion, expected| actual = round(group.coverage_statistics.fetch(criterion).percent) {group_name: group_name, criterion: criterion, expected: expected, actual: actual} if actual < expected end end
.lookup_group(result, group_name) (private)
[ GitHub ]
.maximum_drop(result, thresholds, last_run: SimpleCov::LastRun.read) ⇒ Array<Hash>
# File 'lib/simplecov/coverage_violations.rb', line 37
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
.minimum_by_file(result, thresholds) ⇒ Array<Hash>
# File 'lib/simplecov/coverage_violations.rb', line 21
def minimum_by_file(result, thresholds) thresholds.flat_map do |criterion, expected| result.files.filter_map { |file| file_minimum_violation(file, criterion, expected) } end end
.minimum_by_group(result, thresholds) ⇒ Array<Hash>
# File 'lib/simplecov/coverage_violations.rb', line 28
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>
.round(percent) (private)
[ GitHub ]# File 'lib/simplecov/coverage_violations.rb', line 83
def round(percent) SimpleCov.round_coverage(percent) end