Class: TTNT::TestToCodeMapping
- Inherits:
-
Object
- Object
- TTNT::TestToCodeMapping
- Defined in:
- lib/ttnt/test_to_code_mapping.rb
Constant Summary collapse
- DIRECTORY_SEPARATOR_PLACEHOLDER =
'=+='.freeze
Instance Method Summary collapse
- #append_from_coverage(test, coverage) ⇒ Object
- #get_tests(file:, lineno:) ⇒ Object
-
#initialize(sha) ⇒ TestToCodeMapping
constructor
A new instance of TestToCodeMapping.
- #read_spectra(test:) ⇒ Object
Constructor Details
#initialize(sha) ⇒ TestToCodeMapping
11 12 13 14 15 |
# File 'lib/ttnt/test_to_code_mapping.rb', line 11 def initialize(sha) @sha = sha @repo = Rugged::Repository.discover('.') raise 'Not in a git repository' unless @repo end |
Instance Method Details
#append_from_coverage(test, coverage) ⇒ Object
17 18 19 20 |
# File 'lib/ttnt/test_to_code_mapping.rb', line 17 def append_from_coverage(test, coverage) spectra = normalize_path(select_project_files(spectra_from_coverage(coverage))) save_spectra(test: test, spectra: spectra) end |
#get_tests(file:, lineno:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ttnt/test_to_code_mapping.rb', line 30 def get_tests(file:, lineno:) tests = Set.new all_tests.each do |test| spectra = read_spectra(test: test) lines = spectra[file] next unless lines n = lines.bsearch { |x| x >= lineno } if n == lineno tests << test end end tests end |
#read_spectra(test:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ttnt/test_to_code_mapping.rb', line 22 def read_spectra(test:) if File.exists?(spectra_file(test: test)) JSON.parse(File.read(spectra_file(test: test))) else {} end end |