Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use the same coverage calculation as simplecov-html

  • Loading branch information...
commit 3d463dde87b4dd7f1c4704248278fe5550c958d6 1 parent f42eb8e
@cap10morgan cap10morgan authored
Showing with 13 additions and 11 deletions.
  1. +13 −11 lib/simplecov-rcov.rb
View
24 lib/simplecov-rcov.rb
@@ -6,7 +6,7 @@ def format( result )
@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 = result.covered_percent
+ @total_coverage = coverage(result.files)
template = ERB.new( File.read( "#{File.dirname(__FILE__)}/../views/index.erb.html" ) )
rcov_result = template.result( binding )
@@ -24,16 +24,18 @@ def format( result )
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
+ def lines_of_code(file_list)
+ lines_missed(file_list) + lines_covered(file_list)
+ end
- return result
- end
+ def coverage(file_list)
+ return 100.0 if file_list.length == 0 or lines_of_code(file_list) == 0
+ lines_missed = file_list.map {|f| f.missed_lines.count }.inject(&:+)
- def self.path_result
- File.join( SimpleCov.coverage_path, SimpleCov::Formatter::RcovFormatter::PATH_RESULT )
- end
+ lines_covered(file_list) * 100 / lines_of_code(file_list).to_f
+ end
+
+ def self.path_result
+ File.join( SimpleCov.coverage_path, SimpleCov::Formatter::RcovFormatter::PATH_RESULT )
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.