Class: SimpleCov::Formatter::SimpleFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/formatter/simple_formatter.rb,
sig/simplecov.rbs

Overview

Renders the result as a plain-text string, one section per group. Returns the string; does not write anything to disk.

Instance Method Summary collapse

Instance Method Details

#format(result) ⇒ String

Takes a SimpleCov::Result and generates a string out of it

Parameters:

Returns:

  • (String)


10
11
12
13
# File 'lib/simplecov/formatter/simple_formatter.rb', line 10

def format(result)
  criterion = SimpleCov.coverage_statistics_key(SimpleCov.primary_coverage)
  result.groups.map { |name, files| format_group(name, files, criterion) }.join
end

#format_group(name, files, criterion) ⇒ String

Parameters:

Returns:

  • (String)


17
18
19
20
21
22
23
24
25
# File 'lib/simplecov/formatter/simple_formatter.rb', line 17

def format_group(name, files, criterion)
  header = "Group: #{name}\n#{'=' * 40}\n"
  # The configured primary criterion is enabled, so every result file
  # carries its corresponding statistic despite the nilable public API.
  body = files.map do |file|
    "#{file.filename} (coverage: #{(_ = file.covered_percent(criterion)).floor(2)}%)\n"
  end.join
  "#{header}#{body}\n"
end