Class: RSpec::Coverage::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rspec/coverage/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, coverage = {}) ⇒ Result

Returns a new instance of Result.



32
33
34
# File 'lib/rspec/coverage/result.rb', line 32

def initialize root, coverage={}
  @root, @coverage = root, coverage
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/rspec/coverage/result.rb', line 3

def root
  @root
end

Class Method Details

.traverse(*results, &block) ⇒ Object



8
9
10
# File 'lib/rspec/coverage/result.rb', line 8

def self.traverse *results, &block
  new("", results.shift).traverse(*results, &block).to_h
end

Instance Method Details

#to_hObject



36
37
38
# File 'lib/rspec/coverage/result.rb', line 36

def to_h
  @coverage.dup
end

#traverse(*results, &block) ⇒ Object



12
13
14
# File 'lib/rspec/coverage/result.rb', line 12

def traverse *results, &block
  RSpec::Coverage::Result.new(root, @coverage.dup).traverse!(*results, &block)
end

#traverse!(*results) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/coverage/result.rb', line 16

def traverse! *results
  results.unshift self
  files = results.map(&:keys).flatten.uniq
  files.each do |file|
    next unless file.start_with? root

    lines = results.map{ |r| r[file] || [] }
    len   = lines.map(&:length).max

    @coverage[file] = len.times.map do |i|
      yield file, *lines.map { |ls| ls[i] }
    end
  end
  self
end