Module: WhatToRun

Defined in:
lib/what_to_run.rb,
lib/what_to_run/cli.rb,
lib/what_to_run/differ.rb,
lib/what_to_run/runner.rb,
lib/what_to_run/tracker.rb,
lib/what_to_run/version.rb,
lib/what_to_run/rspec/runner.rb,
lib/what_to_run/minitest/runner.rb

Defined Under Namespace

Modules: Minitest, RSpec Classes: CLI, Differ, Runner, Tracker

Constant Summary collapse

VERSION =
'1.0.2'

Class Method Summary collapse

Class Method Details

.cov_mapObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/what_to_run.rb', line 43

def cov_map
  schema = Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }

  @cov_map ||= Tracker.read.inject(schema) do |cov_map, (desc, cov_delta)|
    cov_delta.each_pair do |file, lines|
      file_map = cov_map[file]

      lines.each_with_index do |line, i|
        file_map[i + 1] << desc if line_executed?(line)
      end
    end

    cov_map
  end
end

.line_executed?(line) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/what_to_run.rb', line 59

def line_executed?(line)
  line.to_i > 0
end

.lines_to_runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/what_to_run.rb', line 17

def lines_to_run
  repository = Rugged::Repository.discover('.')
  repository_root = File.expand_path("..", repository.path)
  lines_to_run = Set.new

  repository.index.diff.each_patch do |patch|
    file = patch.delta.old_file[:path]
    file_path = File.join(repository_root, file)

    patch.each_hunk do |hunk|
      hunk.each_line do |line|
        case line.line_origin
        when :addition
          lines_to_run << [file_path, line.new_lineno]
        when :deletion
          lines_to_run << [file_path, line.old_lineno]
        when :context
          # do nothing
        end
      end
    end
  end

  lines_to_run
end

.predictObject



11
12
13
14
15
# File 'lib/what_to_run.rb', line 11

def predict
  lines_to_run.inject(Set.new) do |tests, (file, line)|
    tests += Array cov_map[file][line]
  end
end