Skip to content

Commit

Permalink
switch back to simplecov's total coverage calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
cap10morgan committed Feb 8, 2011
1 parent 8d03012 commit 3b7b1df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions lib/simplecov-rcov.rb
@@ -1,39 +1,39 @@
class SimpleCov::Formatter::RcovFormatter
PATH_RESULT = "/rcov/index.html"

def format( result )
@files = result.files

@total_lines = result.files.map { |e| e.lines.count }.inject(:+)
@total_lines_code = result.files.map { |e| e.covered_lines.count + e.missed_lines.count }.inject(:+)
@total_coverage = SimpleCov::Formatter::RcovFormatter.total_coverage(@files)
@total_coverage = result.covered_percent

template = ERB.new( File.read( "#{File.dirname(__FILE__)}/../views/index.erb.html" ) )
rcov_result = template.result( binding )

FileUtils.mkdir_p( File.dirname( SimpleCov::Formatter::RcovFormatter.path_result ) )

File.open( SimpleCov::Formatter::RcovFormatter.path_result, "w" ) do |file_result|
file_result.write rcov_result
file_result.write rcov_result
end

puts "Coverage report Rcov style generated for #{result.command_name} to #{SimpleCov::Formatter::RcovFormatter.path_result}"

return rcov_result
end

private

# Computes the coverage based upon lines covered and lines missed
def self.total_coverage(file_list)
return 100.0 if file_list.length == 0
porcents_sum = file_list.map(&:covered_percent).reduce(&:+)
result = porcents_sum / file_list.length

return result
end

def self.path_result
File.join( SimpleCov.coverage_path, SimpleCov::Formatter::RcovFormatter::PATH_RESULT )
end
end
end
4 changes: 2 additions & 2 deletions test/fixtures/totals_tr.html
Expand Up @@ -2,6 +2,6 @@
<td class="left_align">TOTAL</td>
<td class='right_align'><tt>338</tt></td>
<td class='right_align'><tt>299</tt></td>
<td class="left_align"><tt class=''>70.25%</tt></td>
<td class="left_align"><tt class='coverage_total'>70.25%</tt></td>
<td class="left_align"><tt class=''>70.57%</tt></td>
<td class="left_align"><tt class='coverage_total'>70.57%</tt></td>
</tr>

0 comments on commit 3b7b1df

Please sign in to comment.