diff --git a/features/config_tracked_files.feature b/features/config_tracked_files.feature index 305558f4..ba0c4f0c 100644 --- a/features/config_tracked_files.feature +++ b/features/config_tracked_files.feature @@ -16,7 +16,7 @@ Feature: When I open the coverage report generated with `bundle exec rake test` Then I should see the groups: | name | coverage | files | - | All Files | 81.54% | 7 | + | All Files | 76.81% | 7 | And I should see the source files: | name | coverage | diff --git a/lib/simplecov.rb b/lib/simplecov.rb index bdd09294..95da3ebd 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -49,44 +49,28 @@ def start(profile = nil, &block) end # - # Finds files that were to be tracked but were not covered and initializes - # their coverage to zero, with an estimation of the line count. + # Finds files that were to be tracked but were not loaded and initializes + # their coverage to zero. # - def add_uncovered_files(result) + def add_not_loaded_files(result) if @track_files_glob result = result.dup Dir[@track_files_glob].each do |file| absolute = File.expand_path(file) - unless result[absolute] - lines = File.readlines(absolute) - result[absolute] = [0] * lines.count { |l| relevant_line?(l) } - end + result[absolute] ||= [0] * File.foreach(absolute).count end end result end - # - # Determines if a line should be considered by coverage tools. - # This method is just an estimation, but it is not very important - # that it is accurate. It is only used when all lines in a file - # are not covered. As soon as a single line is covered, the counting - # method will be the one provided by the Coverage module. - # - def relevant_line?(line) - l = line.strip - - !(l.empty? || l =~ /^else$/ || l =~ /^end$/ || l[0] == '#' || l =~ /^rescue(\s+.*)?$/) - end - # # Returns the result for the current coverage run, merging it across test suites # from cache using SimpleCov::ResultMerger if use_merging is activated (default) # def result - @result ||= SimpleCov::Result.new(add_uncovered_files(Coverage.result)) if running + @result ||= SimpleCov::Result.new(add_not_loaded_files(Coverage.result)) if running # If we're using merging of results, store the current result # first, then merge the results and return those if use_merging