Class: SimpleCov::Formatter::TextFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-text.rb,
lib/simplecov-text/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#format(result) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simplecov-text.rb', line 7

def format(result)
  output = ""
  output << sprintf("%0.2f", result.covered_percent) << "\n"
  output << "%d of %d lines covered (%0.2f hits per line)" % [
    result.covered_lines,
    result.total_lines,
    result.covered_strength
  ]
  
  result.groups.each do |name, files|
    output << "Group: #{name}" << "\n"
    output << "="*40 << "\n"
    files.each do |file|
      output << "%s (coverage: %0.2f%%)\n" % [
        file.filename,
        file.covered_percent
      ]
    end
    output << "\n"
  end
  
  write_result(output)
end

#pathObject



37
38
39
# File 'lib/simplecov-text.rb', line 37

def path
  File.join(SimpleCov.coverage_path, 'result.txt')
end

#write_result(result) ⇒ Object



31
32
33
34
35
# File 'lib/simplecov-text.rb', line 31

def write_result(result)
  File.open(path, 'w') do |f|
    f.write(result)
  end
end