Class: WTT::Core::Mapper
- Inherits:
-
Object
- Object
- WTT::Core::Mapper
- Defined in:
- lib/wtt/core/mapper.rb
Overview
Mapping from test file to executed code (i.e. coverage without execution count).
Terminologies:
spectra: { filename => [line, numbers, executed], ... }
mapping: { test_file => spectra }
Constant Summary collapse
- STORAGE_SECTION =
'mapping'.freeze
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
-
#append_from_coverage(test, coverage) ⇒ void
Append the new mapping to test-to-code mapping file.
-
#append_from_simplecov(test, coverage) ⇒ void
Append the new mapping to test-to-code mapping file.
-
#get_tests(file, lineno) ⇒ Set
Get tests affected from change of file ‘file` at line number `lineno`.
-
#initialize(storage) ⇒ Mapper
constructor
A new instance of Mapper.
- #matcher ⇒ Object
-
#read! ⇒ Object
Read test-to-code mapping from storage.
- #unmapped_tests ⇒ Object
-
#write! ⇒ Object
Write test-to-code mapping to storage.
Constructor Details
#initialize(storage) ⇒ Mapper
Returns a new instance of Mapper.
21 22 23 24 |
# File 'lib/wtt/core/mapper.rb', line 21 def initialize(storage) @storage = storage read! end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
18 19 20 |
# File 'lib/wtt/core/mapper.rb', line 18 def mapping @mapping end |
Instance Method Details
#append_from_coverage(test, coverage) ⇒ void
This method returns an undefined value.
Append the new mapping to test-to-code mapping file.
35 36 37 38 |
# File 'lib/wtt/core/mapper.rb', line 35 def append_from_coverage(test, coverage) spectra = normalize_paths(select_project_files(spectra_from_coverage(coverage))) @mapping[test] = spectra end |
#append_from_simplecov(test, coverage) ⇒ void
This method returns an undefined value.
Append the new mapping to test-to-code mapping file.
45 46 47 48 |
# File 'lib/wtt/core/mapper.rb', line 45 def append_from_simplecov(test, coverage) spectra = normalize_paths(select_project_files(spectra_from_simplecov(coverage))) @mapping[test] = spectra end |
#get_tests(file, lineno) ⇒ Set
Get tests affected from change of file ‘file` at line number `lineno`
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wtt/core/mapper.rb', line 65 def get_tests(file, lineno) tests = Set.new @mapping.each do |test, spectra| lines = spectra[file] next unless lines tests << test if matcher.match(lines, lineno) end warn "No tests found for #{file}:#{lineno}." if file.end_with?('.rb') tests end |
#matcher ⇒ Object
26 27 28 |
# File 'lib/wtt/core/mapper.rb', line 26 def matcher @matcher ||= WTT.configuration.matcher end |
#read! ⇒ Object
Read test-to-code mapping from storage.
51 52 53 |
# File 'lib/wtt/core/mapper.rb', line 51 def read! @mapping = @storage.read(STORAGE_SECTION) end |
#unmapped_tests ⇒ Object
76 77 78 |
# File 'lib/wtt/core/mapper.rb', line 76 def unmapped_tests @mapping.select { |_test, spectra| spectra.count == 0 }.keys end |
#write! ⇒ Object
Write test-to-code mapping to storage.
56 57 58 |
# File 'lib/wtt/core/mapper.rb', line 56 def write! @storage.write!(STORAGE_SECTION, @mapping) end |