Class: RSpecTracer::CoverageMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_tracer/coverage_merger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCoverageMerger

Returns a new instance of CoverageMerger.



7
8
9
# File 'lib/rspec_tracer/coverage_merger.rb', line 7

def initialize
  @coverage = {}
end

Instance Attribute Details

#coverageObject (readonly)

Returns the value of attribute coverage.



5
6
7
# File 'lib/rspec_tracer/coverage_merger.rb', line 5

def coverage
  @coverage
end

Instance Method Details

#merge(reports_dir) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec_tracer/coverage_merger.rb', line 11

def merge(reports_dir)
  return if RSpecTracer.simplecov?

  reports_dir.each do |report_dir|
    next unless File.directory?(report_dir)

    cache_coverage = JSON.parse(File.read("#{report_dir}/coverage.json"))['RSpecTracer']['coverage']

    cache_coverage.each_pair do |file_name, line_coverage|
      unless @coverage.key?(file_name)
        @coverage[file_name] = line_coverage

        next
      end

      merge_line_coverage(file_name, line_coverage)
    end
  end
end