123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::ExitCodes::MaximumCoverageDropCheck

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

Overview

Fails when any coverage criterion has dropped by more than the configured maximum since the last recorded run.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(result, maximum_coverage_drop) ⇒ MaximumCoverageDropCheck

[ GitHub ]

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

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

Instance Attribute Details

#failing?Boolean (readonly)

[ GitHub ]

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

def failing?
  violations.any?
end

Instance Method Details

#exit_code

[ GitHub ]

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

def exit_code
  SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
end

#message_for(violation) (private)

The "drop percent" is a delta, not a coverage level — it has no natural green/yellow/red mapping. Callers color the whole line red so the failure is still visible at a glance.

[ GitHub ]

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

def message_for(violation)
  format(
    "%<criterion>s coverage has dropped by %<drop_percent>.2f%% since the last time " \
    "(maximum allowed: %<max_drop>.2f%%).",
    criterion: violation.fetch(:criterion).capitalize,
    drop_percent: violation.fetch(:actual),
    max_drop: violation.fetch(:maximum)
  )
end

#report

[ GitHub ]

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

def report
  violations.each { |violation| warn SimpleCov::Color.colorize(message_for(violation), :red) }
end

#violations (private)

[ GitHub ]

  
# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 40

def violations
  @violations ||= SimpleCov::CoverageViolations.maximum_drop(@result, @maximum_coverage_drop)
end