Class: SimpleCov::ExitCodes::MaximumCoverageDropCheck
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/simplecov/exit_codes/maximum_coverage_drop_check.rb |
Constant Summary
-
MAX_DROP_ACCURACY =
if anyone says “max_coverage_drop 0.000000000000000001” I appologize. Please don’t.
10
Class Method Summary
Instance Attribute Summary
- #failing? ⇒ Boolean readonly
- #maximum_coverage_drop readonly private
- #result readonly private
Instance Method Summary
- #exit_code
- #report
- #compute_coverage_drop_data private
- #coverage_drop_violations private
- #drop_percent(criterion) private
- #last_coverage(criterion) private
- #last_run private
Constructor Details
.new(result, maximum_coverage_drop) ⇒ MaximumCoverageDropCheck
# 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
Instance Attribute Details
#failing? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 11
def failing? return false unless maximum_coverage_drop && last_run coverage_drop_violations.any? end
#maximum_coverage_drop (readonly, private)
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 34
attr_reader :result, :maximum_coverage_drop
#result (readonly, private)
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 34
attr_reader :result, :maximum_coverage_drop
Instance Method Details
#compute_coverage_drop_data (private)
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 49
def compute_coverage_drop_data maximum_coverage_drop.map do |criterion, percent| { criterion: criterion, max_drop: percent, drop_percent: drop_percent(criterion) } end end
#coverage_drop_violations (private)
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 42
def coverage_drop_violations @coverage_drop_violations ||= compute_coverage_drop_data.select do |achieved| achieved.fetch(:max_drop) < achieved.fetch(:drop_percent) end end
#drop_percent(criterion) (private)
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 61
def drop_percent(criterion) drop = last_coverage(criterion) - SimpleCov.round_coverage( result.coverage_statistics.fetch(criterion).percent ) # floats, I tell ya. # irb(main):001:0* 80.01 - 80.0 # => 0.010000000000005116 drop.floor(MAX_DROP_ACCURACY) end
#exit_code
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 28
def exit_code SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP end
#last_coverage(criterion) (private)
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 73
def last_coverage(criterion) last_coverage_percent = last_run[:result][criterion] # fallback for old file format last_coverage_percent = last_run[:result][:covered_percent] if !last_coverage_percent && criterion == :line last_coverage_percent || 0 end
#last_run (private)
[ GitHub ]#report
[ GitHub ]# File 'lib/simplecov/exit_codes/maximum_coverage_drop_check.rb', line 17
def report coverage_drop_violations.each do |violation| $stderr.printf( "%<criterion>s coverage has dropped by %<drop_percent>.2f%% since the last time (maximum allowed: %<max_drop>.2f%%).\n", criterion: violation[:criterion].capitalize, drop_percent: SimpleCov.round_coverage(violation[:drop_percent]), max_drop: violation[:max_drop] ) end end