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

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 6

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 11

def failing?
  minimum_violations.any?
end

#minimum_coverage (readonly, private)

[ GitHub ]

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

attr_reader :result, :minimum_coverage

#result (readonly, private)

[ GitHub ]

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

attr_reader :result, :minimum_coverage

Instance Method Details

#calculate_minimum_violations (private)

[ GitHub ]

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

def calculate_minimum_violations
  coverage_achieved = minimum_coverage.map do |criterion, percent|
    {
      criterion: criterion,
      minimum_expected: percent,
      actual: result.coverage_statistics.fetch(criterion).percent
    }
  end

  coverage_achieved.select do |achieved|
    achieved.fetch(:actual) < achieved.fetch(:minimum_expected)
  end
end

#exit_code

[ GitHub ]

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

def exit_code
  SimpleCov::ExitCodes::MINIMUM_COVERAGE
end

#minimum_violations (private)

[ GitHub ]

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

def minimum_violations
  @minimum_violations ||= calculate_minimum_violations
end

#report

[ GitHub ]

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

def report
  minimum_violations.each do |violation|
    $stderr.printf(
      "%<criterion>s coverage (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%).\n",
      covered: SimpleCov.round_coverage(violation.fetch(:actual)),
      minimum_coverage: violation.fetch(:minimum_expected),
      criterion: violation.fetch(:criterion).capitalize
    )
  end
end