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
# File 'lib/simplecov/formatter/simple_formatter.rb', line 10

def format(result)
  result.groups.map { |name, files| format_group(name, files) }.join
end

#format_group(name, files) ⇒ String

Parameters:

Returns:

  • (String)


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

def format_group(name, files)
  header = "Group: #{name}\n#{'=' * 40}\n"
  # `covered_percent` is nilable across criteria, but line stats are
  # always measured, so the no-argument call can't return nil here.
  body   = files.map { |file| "#{file.filename} (coverage: #{(_ = file.covered_percent).floor(2)}%)\n" }.join
  "#{header}#{body}\n"
end