Class: WhatToRun::Differ

Inherits:
Object
  • Object
show all
Defined in:
lib/what_to_run/differ.rb

Class Method Summary collapse

Class Method Details

.coverage_delta(cov_before, cov_after, cov_before_suite) ⇒ Object

Gives the delta beteween the coverage result before and after a test run and before starting the test suite

Results in the lines that may trigger the test that gave the after result



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/what_to_run/differ.rb', line 11

def coverage_delta(cov_before, cov_after, cov_before_suite)
  cov_after.each_with_object({}) do |(file_name, lines_cov_after), delta|
    lines_cov_before = cov_before[file_name]
    lines_cov_before_suite = cov_before_suite[file_name]

    next unless file_covered?(lines_cov_before, lines_cov_after)

    lines_delta = lines_cov_delta \
      lines_cov_before_suite, lines_cov_before, lines_cov_after

    delta[file_name] = lines_delta
  end
end

.diff(before, after) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/what_to_run/differ.rb', line 35

def diff(before, after)
  after = Array(after)
  before = Array(before)

  after.zip(before).map do |lines_after, lines_before|
    lines_after ? lines_after - lines_before.to_i : lines_after
  end
end

.normalize_cov_result(result) ⇒ Object

The possible param value that this method might receive are the following

This method will convert negative and nil values to 1, which will make them represent lines that should be run. The positive lines can be kept as they are since this mean they will be run.

The only exception case is the 0 result which will be kept as it is so we don’t run lines within the not called methods

This introduces false positives to avoid missing tests that depends on lines that are evaluated when the file is required

Parameters:

  • result

    positive => should run the test

  • result

    negative => should run the test

  • result

    nil => should run the test

  • result

    zero => should not run the test

Returns:

  • 1 to represent that this line should trigger the current test

  • 0 to represent that this line should not trigger the current test



66
67
68
# File 'lib/what_to_run/differ.rb', line 66

def normalize_cov_result(result)
  result.nil? || result.to_i < 0 ? 1 : result
end