Class: MissCleo::CoverageMap

Inherits:
Object
  • Object
show all
Defined in:
lib/miss_cleo/coverage_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map = nil) ⇒ CoverageMap

Returns a new instance of CoverageMap.



6
7
8
# File 'lib/miss_cleo/coverage_map.rb', line 6

def initialize(map = nil)
  @map = map || Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



4
5
6
# File 'lib/miss_cleo/coverage_map.rb', line 4

def map
  @map
end

Instance Method Details

#add_to_coverage_map(test_diffs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/miss_cleo/coverage_map.rb', line 10

def add_to_coverage_map(test_diffs)
  test_diffs.each do |test_to_code_map|
    test_file_and_line = test_to_code_map.first
    before = test_to_code_map.last["before"]
    after = test_to_code_map.last["after"]
    templates = test_to_code_map.last["templates"]

    # calculate the per test coverage
    delta = diff before, after
    add_delta_to_map(delta, test_file_and_line)
    add_templates_to_map(templates, test_file_and_line)
  end

  nil
end

#tests_for_lines(file, line) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/miss_cleo/coverage_map.rb', line 26

def tests_for_lines(file, line)
  begin
    # NOTE: This is currently how templates and non-templates are being
    # split. Since I will likely have to cover a bunch of blind spots
    # manually like this, this probably needs to be rearchitected.
    if file.include?("app/views")
      map[file]["0"].uniq || []
    else
      map[file][line.to_s].uniq || []
    end
  rescue
    []
  end
end