Module: ActiveMutator::BaselineHooks

Defined in:
lib/active_mutator/baseline_hooks.rb

Constant Summary collapse

RECORDS =
{}
TIMES =
{}

Class Method Summary collapse

Class Method Details

.build_payload(records, times, expected_examples: nil) ⇒ Object



36
37
38
39
40
# File 'lib/active_mutator/baseline_hooks.rb', line 36

def self.build_payload(records, times, expected_examples: nil)
  payload = { "version" => 2, "records" => records, "times" => times }
  payload["expected_examples"] = expected_examples if expected_examples
  payload
end

.diff_coverage(before, after, root, spec_paths: ["spec"]) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_mutator/baseline_hooks.rb', line 12

def self.diff_coverage(before, after, root, spec_paths: ["spec"])
  prefixes = spec_paths.map { |sp| "/#{sp}/" }
  hits = []
  after.each do |path, data|
    next unless path.start_with?(root)

    # Relative to root, not a global substring check: `root` itself may
    # contain "/spec/" (e.g. a fixture nested under this gem's own
    # spec/fixtures/ tree), which would otherwise falsely exclude every
    # file under it.
    relative = path.delete_prefix(root)
    next if prefixes.any? { |p| relative.start_with?(p) }

    before_lines = before.dig(path, :lines)
    data[:lines].each_with_index do |count, idx|
      next if count.nil?

      previous = before_lines ? before_lines[idx].to_i : 0
      hits << [path, idx + 1] if count > previous
    end
  end
  hits
end