Class: RSpec::Covers::Probe::CoverageProbe

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/covers/probe/coverage_probe.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CoverageProbe

Returns a new instance of CoverageProbe.



11
12
13
14
# File 'lib/rspec/covers/probe/coverage_probe.rb', line 11

def initialize(config)
  @config = config
  @started = false
end

Instance Method Details

#difference(before_snapshot, after_snapshot) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/covers/probe/coverage_probe.rb', line 28

def difference(before_snapshot, after_snapshot)
  after_snapshot.each_with_object(Set.new) do |(file, lines), executed|
    next unless @config.production_file?(file)

    previous = before_snapshot.fetch(file, [])
    lines.each_with_index do |count, index|
      next unless count && count > previous.fetch(index, 0).to_i

      executed << CodeLocation.new(file: file, line: index + 1)
    end
  end
end

#snapshotObject



23
24
25
26
# File 'lib/rspec/covers/probe/coverage_probe.rb', line 23

def snapshot
  start
  normalize(Coverage.peek_result)
end

#startObject



16
17
18
19
20
21
# File 'lib/rspec/covers/probe/coverage_probe.rb', line 16

def start
  return if @started

  Coverage.start(lines: true) unless Coverage.running?
  @started = true
end