class SimpleCov::ExitCodes::MaximumCoverageDropCheck

Attributes

maximum_coverage_drop[R]
result[R]

Public Class Methods

new(result, maximum_coverage_drop) click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 6
def initialize(result, maximum_coverage_drop)
  @result = result
  @maximum_coverage_drop = maximum_coverage_drop
end

Public Instance Methods

exit_code() click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 25
def exit_code
  SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
end
failing?() click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 11
def failing?
  return false unless maximum_coverage_drop && last_run

  coverage_diff > maximum_coverage_drop
end
report() click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 17
def report
  $stderr.printf(
    "Coverage has dropped by %<drop_percent>.2f%% since the last time (maximum allowed: %<max_drop>.2f%%).\n",
    drop_percent: coverage_diff,
    max_drop: maximum_coverage_drop
  )
end

Private Instance Methods

coverage_diff() click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 39
def coverage_diff
  raise "Trying to access coverage_diff although there is no last run" unless last_run

  @coverage_diff ||= last_run[:result][:covered_percent] - covered_percent
end
covered_percent() click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 45
def covered_percent
  SimpleCov.round_coverage(result.covered_percent)
end
last_run() click to toggle source
# File lib/simplecov/exit_codes/maximum_coverage_drop_check.rb, line 33
def last_run
  return @last_run if defined?(@last_run)

  @last_run = SimpleCov::LastRun.read
end