123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::ExitCodes::MinimumCoverageByFileCheck

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(result, minimum_coverage_by_file) ⇒ MinimumCoverageByFileCheck

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb', line 6

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

Instance Attribute Details

#failing?Boolean (readonly)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb', line 11

def failing?
  minimum_violations.any?
end

#minimum_coverage_by_file (readonly, private)

[ GitHub ]

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

attr_reader :result, :minimum_coverage_by_file

#result (readonly, private)

[ GitHub ]

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

attr_reader :result, :minimum_coverage_by_file

Instance Method Details

#compute_minimum_coverage_data (private)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb', line 41

def compute_minimum_coverage_data
  minimum_coverage_by_file.flat_map do |criterion, expected_percent|
    result.coverage_statistics_by_file.fetch(criterion).map do |actual_coverage|
      {
        criterion: criterion,
        minimum_expected: expected_percent,
        actual: SimpleCov.round_coverage(actual_coverage.percent)
      }
    end
  end
end

#exit_code

[ GitHub ]

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

def exit_code
  SimpleCov::ExitCodes::MINIMUM_COVERAGE
end

#minimum_violations (private)

[ GitHub ]

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

def minimum_violations
  @minimum_violations ||=
    compute_minimum_coverage_data.select do |achieved|
      achieved.fetch(:actual) < achieved.fetch(:minimum_expected)
    end
end

#report

[ GitHub ]

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

def report
  minimum_violations.each do |violation|
    $stderr.printf(
      "%<criterion>s coverage by file (%<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