Class: MissCleo::CoverageMap
- Inherits:
-
Object
- Object
- MissCleo::CoverageMap
- Defined in:
- lib/miss_cleo/coverage_map.rb
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_coverage_map(test_diffs) ⇒ Object
-
#initialize(map = nil) ⇒ CoverageMap
constructor
A new instance of CoverageMap.
- #tests_for_lines(file, line) ⇒ Object
Constructor Details
#initialize(map = nil) ⇒ CoverageMap
Returns a new instance of CoverageMap.
23 24 25 |
# File 'lib/miss_cleo/coverage_map.rb', line 23 def initialize(map = nil) @map = map || Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } } end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
21 22 23 |
# File 'lib/miss_cleo/coverage_map.rb', line 21 def map @map end |
Class Method Details
.build(file_names) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/miss_cleo/coverage_map.rb', line 4 def self.build(file_names) cov_map = self.new file_names.each do |file_name| File.open(file_name, "r") do |f| f.read end.tap do |contents| begin cov_map.add_to_coverage_map(JSON.parse(contents)) rescue puts "#{file_name} is malformed, this may affect test predictons" end end end cov_map end |
Instance Method Details
#add_to_coverage_map(test_diffs) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/miss_cleo/coverage_map.rb', line 27 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/miss_cleo/coverage_map.rb', line 43 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 |