Class: SimpleCov::Formatter::JSONFormatter::ResultHashFormatter
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/simplecov/formatter/json_formatter/result_hash_formatter.rb |
Constant Summary
-
CRITERION_KEYS =
private
# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 48{line: :lines, branch: :branches, method: :methods}.freeze
Class Method Summary
- .new(result) ⇒ ResultHashFormatter constructor
Instance Method Summary
- #format
- #format_coverage_statistics(statistics) private
- #format_errors private
- #format_files private
- #format_groups private
- #format_line_statistic(stat) private
- #format_maximum_coverage_drop_errors private
- #format_minimum_coverage_by_file_errors private
- #format_minimum_coverage_by_group_errors private
- #format_minimum_coverage_errors private
- #format_single_statistic(stat) private
- #format_source_file(source_file) private
- #format_total private
- #formatted_result private
Constructor Details
.new(result) ⇒ ResultHashFormatter
Instance Method Details
#format
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 13
def format format_total format_files format_groups format_errors formatted_result end
#format_coverage_statistics(statistics) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 102
def format_coverage_statistics(statistics) result = {lines: format_line_statistic(statistics[:line])} result[:branches] = format_single_statistic(statistics[:branch]) if SimpleCov.branch_coverage? && statistics[:branch] result[:methods] = format_single_statistic(statistics[:method]) if SimpleCov.method_coverage? && statistics[:method] result end
#format_errors (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 41
def format_errors format_minimum_coverage_errors format_minimum_coverage_by_file_errors format_minimum_coverage_by_group_errors format_maximum_coverage_drop_errors end
#format_files (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 28
def format_files @result.files.each do |source_file| formatted_result[:coverage][source_file.filename] = format_source_file(source_file) end end
#format_groups (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 35
def format_groups @result.groups.each do |name, file_list| formatted_result[:groups][name] = format_coverage_statistics(file_list.coverage_statistics) end end
#format_line_statistic(stat) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 109
def format_line_statistic(stat) { covered: stat.covered, missed: stat.missed, omitted: stat.omitted, total: stat.total, percent: stat.percent, strength: stat.strength } end
#format_maximum_coverage_drop_errors (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 77
def format_maximum_coverage_drop_errors SimpleCov::CoverageViolations.maximum_drop(@result, SimpleCov.maximum_coverage_drop).each do |violation| key = CRITERION_KEYS.fetch(violation.fetch(:criterion)) bucket = formatted_result[:errors][:maximum_coverage_drop] ||= {} bucket[key] = {maximum: violation.fetch(:maximum), actual: violation.fetch(:actual)} end end
#format_minimum_coverage_by_file_errors (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 59
def format_minimum_coverage_by_file_errors SimpleCov::CoverageViolations.minimum_by_file(@result, SimpleCov.minimum_coverage_by_file).each do |violation| key = CRITERION_KEYS.fetch(violation.fetch(:criterion)) bucket = formatted_result[:errors][:minimum_coverage_by_file] ||= {} criterion_errors = bucket[key] ||= {} criterion_errors[violation.fetch(:filename)] = {expected: violation.fetch(:expected), actual: violation.fetch(:actual)} end end
#format_minimum_coverage_by_group_errors (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 68
def format_minimum_coverage_by_group_errors SimpleCov::CoverageViolations.minimum_by_group(@result, SimpleCov.minimum_coverage_by_group).each do |violation| key = CRITERION_KEYS.fetch(violation.fetch(:criterion)) bucket = formatted_result[:errors][:minimum_coverage_by_group] ||= {} group_errors = bucket[violation.fetch(:group_name)] ||= {} group_errors[key] = {expected: violation.fetch(:expected), actual: violation.fetch(:actual)} end end
#format_minimum_coverage_errors (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 51
def format_minimum_coverage_errors SimpleCov::CoverageViolations.minimum_overall(@result, SimpleCov.minimum_coverage).each do |violation| key = CRITERION_KEYS.fetch(violation.fetch(:criterion)) bucket = formatted_result[:errors][:minimum_coverage] ||= {} bucket[key] = {expected: violation.fetch(:expected), actual: violation.fetch(:actual)} end end
#format_single_statistic(stat) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 120
def format_single_statistic(stat) { covered: stat.covered, missed: stat.missed, total: stat.total, percent: stat.percent, strength: stat.strength } end
#format_source_file(source_file) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 97
def format_source_file(source_file) source_file_formatter = SourceFileFormatter.new(source_file) source_file_formatter.format end
#format_total (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/result_hash_formatter.rb', line 24
def format_total formatted_result[:total] = format_coverage_statistics(@result.coverage_statistics) end