Class: Evilution::Coverage::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/coverage/recorder.rb

Overview

Wraps each example with a before/after coverage diff and attributes the newly-executed lines (in target files only) to that example’s location. coverage_source is injected for testability; in production it is -> { ::Coverage.peek_result }.

Instance Method Summary collapse

Constructor Details

#initialize(target_files:, coverage_source: -> { ::Coverage.peek_result }) ⇒ Recorder

Returns a new instance of Recorder.



11
12
13
14
15
16
# File 'lib/evilution/coverage/recorder.rb', line 11

def initialize(target_files:, coverage_source: -> { ::Coverage.peek_result })
  @target_files = target_files.to_a
  @coverage_source = coverage_source
  @index = Hash.new { |h, file| h[file] = Hash.new { |g, line| g[line] = [] } }
  @executed = Hash.new { |h, file| h[file] = [] }
end

Instance Method Details

#around_example(example_location) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/evilution/coverage/recorder.rb', line 18

def around_example(example_location)
  before = snapshot
  result = yield
  after = snapshot
  attribute(before, after, example_location)
  result
end

#to_map(built_files:) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/evilution/coverage/recorder.rb', line 26

def to_map(built_files:)
  Evilution::Coverage::Map.new(
    index: materialize(@index),
    built_files: built_files,
    executed_lines: @executed.transform_values(&:uniq)
  )
end