123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::Formatter::JSONFormatter::ErrorsFormatter

Relationships & Source Files
Inherits: Object
Defined in: lib/simplecov/formatter/json_formatter/errors_formatter.rb

Overview

Translates the threshold violations reported by ::SimpleCov::CoverageViolations into the :errors section of coverage.json. Each violation is keyed by criterion (:lines / :branches / :methods) so consumers can render per-criterion messages without re-deriving them.

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(result) ⇒ ErrorsFormatter

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 15

def initialize(result)
  @result = result
  @errors = {}
end

Instance Method Details

#bucket(name) (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 70

def bucket(name)
  @errors[name] ||= {}
end

#call

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 20

def call
  format_minimum_overall
  format_minimum_by_file
  format_minimum_by_group
  format_maximum_overall
  format_maximum_drop
  @errors
end

#expected_actual(violation) (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 78

def expected_actual(violation)
  {expected: violation.fetch(:expected), actual: violation.fetch(:actual)}
end

#format_maximum_drop (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 63

def format_maximum_drop
  SimpleCov::CoverageViolations.maximum_drop(@result, SimpleCov.maximum_coverage_drop).each do |violation|
    bucket(:maximum_coverage_drop)[key_for(violation)] =
      {maximum: violation.fetch(:maximum), actual: violation.fetch(:actual)}
  end
end

#format_maximum_overall (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 57

def format_maximum_overall
  SimpleCov::CoverageViolations.maximum_overall(@result, SimpleCov.maximum_coverage).each do |violation|
    bucket(:maximum_coverage)[key_for(violation)] = expected_actual(violation)
  end
end

#format_minimum_by_file (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 37

def format_minimum_by_file
  violations = SimpleCov::CoverageViolations.minimum_by_file(
    @result, SimpleCov.minimum_coverage_by_file, SimpleCov.minimum_coverage_by_file_overrides
  )
  violations.each { |violation| record_by_file(violation) }
end

#format_minimum_by_group (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 49

def format_minimum_by_group
  violations = SimpleCov::CoverageViolations.minimum_by_group(@result, SimpleCov.minimum_coverage_by_group)
  violations.each do |violation|
    group_bucket = bucket(:minimum_coverage_by_group)[violation.fetch(:group_name)] ||= {}
    group_bucket[key_for(violation)] = expected_actual(violation)
  end
end

#format_minimum_overall (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 31

def format_minimum_overall
  SimpleCov::CoverageViolations.minimum_overall(@result, SimpleCov.minimum_coverage).each do |violation|
    bucket(:minimum_coverage)[key_for(violation)] = expected_actual(violation)
  end
end

#key_for(violation) (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 74

def key_for(violation)
  CRITERION_KEYS.fetch(SimpleCov.coverage_statistics_key(violation.fetch(:criterion)))
end

#record_by_file(violation) (private)

[ GitHub ]

  
# File 'lib/simplecov/formatter/json_formatter/errors_formatter.rb', line 44

def record_by_file(violation)
  file_bucket = bucket(:minimum_coverage_by_file)[violation.fetch(:project_filename)] ||= {}
  file_bucket[key_for(violation)] = expected_actual(violation)
end