lib/undercover.rb in undercover-0.1.7 vs lib/undercover.rb in undercover-0.2.0

- old
+ new

@@ -24,22 +24,24 @@ :results, :code_dir # Initializes a new Undercover::Report # - # @param options [Undercover::Options] - def initialize(opts) + # @param changeset [Undercover::Changeset] + # @param opts [Undercover::Options] + def initialize(changeset, opts) @lcov = LcovParser.parse(File.open(opts.lcov)) @code_dir = opts.path - git_dir = File.join(opts.path, opts.git_dir) - @changeset = Changeset.new(git_dir, opts.compare).update - @results = Hash.new { |hsh, key| hsh[key] = [] } + @changeset = changeset.update + @results = {} end def build each_result_arg do |filename, coverage, imagen_node| - results[filename.gsub(/^\.\//, '')] << Result.new( + key = filename.gsub(/^\.\//, '') + results[key] ||= [] + results[key] << Result.new( imagen_node, coverage, filename ) end self end @@ -55,10 +57,11 @@ end dist_from_line_no_sorter = lambda do |res1, res2| dist_from_line_no[res1] <=> dist_from_line_no[res2] end + next unless results[filepath] res = results[filepath].min(&dist_from_line_no_sorter) flagged_results << res if res&.uncovered?(line_no) end flagged_results end @@ -78,15 +81,15 @@ # TODO: should that start from changeset.file_paths? # this way we could report things that weren't even loaded in any spec, # so is this still good idea? (Rakefile, .gemspec etc) def each_result_arg match_all = ->(_) { true } - lcov.source_files.each do |filename, coverage| - path = File.join(code_dir, filename) + lcov.source_files.each do |relative_filename, coverage| + path = File.join(code_dir, relative_filename) root_ast = Imagen::Node::Root.new.build_from_file(path) next if root_ast.children.empty? root_ast.children[0].find_all(match_all).each do |node| - yield(path, coverage, node) + yield(relative_filename, coverage, node) end end end end end