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)
  $stderr.printf(
    "%<criterion>s coverage (%<covered>.2f%%) is below the expected minimum coverage " \
    "(%<minimum_coverage>.2f%%).\n",
    covered: violation.fetch(:actual),
    minimum_coverage: violation.fetch(:expected),
    criterion: criterion.capitalize
  )
  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>6.2f%%  %<path>s", percent: 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 56

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