This commit is contained in:
Robert Lail 2013-03-18 19:25:58 -05:00
parent e4d8b177b1
commit ad09e37eeb

View File

@ -2,14 +2,15 @@ require 'simplecov'
require 'json'
class SimpleCov::Formatter::JSONFormatter
def format(result)
puts result.inspect
data = {}
data[:timestamp] = result.created_at.to_i
data[:command_name] = result.command_name
data[:files] = []
result.original_result.each do |filename,coverage|
result.original_result.each do |filename, coverage|
next unless result.filenames.include? filename
data[:files] << {
filename: filename,
coverage: coverage
@ -27,26 +28,28 @@ class SimpleCov::Formatter::JSONFormatter
File.open(output_filepath, "w+") do |file|
file.puts json
end
puts output_message(result)
json
end
def output_filename
'coverage.json'
end
def output_filepath
File.join(output_path, output_filename)
end
def output_message(result)
"Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
end
private
private
def output_path
SimpleCov.coverage_path
end
end