class Covered::Statistics
def self.for(coverage)
def self.for(coverage) self.new.tap do |statistics| statistics << coverage end end
def << coverage
def << coverage @count += 1 @executable_count += coverage.executable_count @executed_count += coverage.executed_count end
def as_json
def as_json { count: count, executable_count: executable_count, executed_count: executed_count, percentage: percentage.to_f.round(2), } end
def initialize
def initialize @count = 0 @executable_count = 0 @executed_count = 0 end
def print(output)
def print(output) output.puts "* #{count} files checked; #{executed_count}/#{executable_count} lines executed; #{percentage.to_f.round(2)}% covered." # Could output funny message here, especially for 100% coverage. end
def to_json(options)
def to_json(options) as_json.to_json(options) end
def validate!(minimum = 1.0)
def validate!(minimum = 1.0) if self.ratio < minimum raise CoverageError, "Coverage of #{self.percentage.to_f.round(2)}% is less than required minimum of #{(minimum * 100.0).round(2)}%!" end end