123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::ExitCodes::MinimumOverallCoverageCheck

Relationships & Source Files
Inherits: Object
Defined in: lib/simplecov/exit_codes/minimum_overall_coverage_check.rb

Overview

Fails when the overall (project-wide) coverage for any criterion is below the configured minimum.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(result, minimum_coverage) ⇒ MinimumOverallCoverageCheck

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 8

def initialize(result, minimum_coverage)
  @result = result
  @minimum_coverage = minimum_coverage
end

Instance Attribute Details

#failing?Boolean (readonly)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 13

def failing?
  violations.any?
end

Instance Method Details

#exit_code

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 21

def exit_code
  SimpleCov::ExitCodes::MINIMUM_COVERAGE
end

#report

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 17

def report
  violations.each { |violation| report_violation(violation) }
end

#report_violation(violation) (private)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 34

def report_violation(violation)
  criterion = violation.fetch(:criterion)
  actual = violation.fetch(:actual)
  warn format(
    "%<criterion>s coverage (%<actual>s) is below the expected minimum coverage (%<expected>.2f%%).",
    criterion: criterion.capitalize,
    actual: SimpleCov::Color.colorize_percent(actual),
    expected: violation.fetch(:expected)
  )
  report_worst_files(criterion)
end

#report_worst_files(criterion) (private)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 46

def report_worst_files(criterion)
  worst = worst_files_for(criterion)
  return if worst.empty?

  warn "  Lowest-coverage files (#{criterion}):"
  worst.each do |path, percent|
    warn format(
      "    %<percent>s  %<path>s",
      percent: SimpleCov::Color.colorize_percent(percent, format("%6.2f%%", percent)),
      path: path
    )
  end
end

#violations (private)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 30

def violations
  @violations ||= SimpleCov::CoverageViolations.minimum_overall(@result, @minimum_coverage)
end

#worst_files_for(criterion) (private)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_overall_coverage_check.rb', line 60

def worst_files_for(criterion)
  stats_key = SimpleCov.coverage_statistics_key(criterion)
  with_stats = @result.files.filter_map do |source_file|
    stats = source_file.coverage_statistics[stats_key]
    [source_file.project_filename, stats.percent] if stats
  end
  with_stats.sort_by { |_path, percent| percent }.first(WORST_FILES_LIMIT)
end