Class: SimpleCov::Formatter::CSVFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-csv.rb

Constant Summary collapse

RESULT_FILE_NAME =
"results.csv"

Instance Method Summary collapse

Instance Method Details

#format(result) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/simplecov-csv.rb', line 4

def format( result )
  csv = "File,% covered,Lines,Relevant Lines,Lines covered,Lines missed\n"

  result.files.each do |file|
    csv << "\"#{shortened_filename file}\","
    csv << "#{file.covered_percent.round.to_s},"
    csv << "#{file.lines.count},"
    csv << "#{file.covered_lines.count + file.missed_lines.count},"
    csv << "#{file.covered_lines.count},"
    csv << "#{file.missed_lines.count}\n"
  end
  
  result_file_path = File.join( SimpleCov.coverage_path, SimpleCov::Formatter::CSVFormatter.result_file_name )
  File.open( result_file_path, "w" ) do |file_result|
    file_result.write csv
  end
  puts "Coverage report generated for #{result.command_name} to #{result_file_path}"
  
  return csv
end