Class: TestLauncher::Frameworks::Minitest::Searcher
Constant Summary
collapse
- MultipleByLineMatches =
Class.new(BaseError)
Instance Attribute Summary
#raw_searcher
Instance Method Summary
collapse
#examples, #grep, #test_files
Instance Method Details
#by_line(file_pattern, line_number) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/test_launcher/frameworks/minitest.rb', line 28
def by_line(file_pattern, line_number)
files = test_files(file_pattern)
return [] unless files.any?
raise multiple_files_error if files.size > 1
file = files.first
grep_results = raw_searcher.grep(example_name_regex, file_pattern: file)
if grep_results.empty?
return [file: file]
end
best_result =
grep_results
.select {|r| line_number >= r[:line_number]}
.min_by {|r| line_number - r[:line_number]}
if best_result
[{
file: best_result[:file],
example_name: best_result[:line].match(/(def\s+(?<name>test_[\w\?]+)|test\s+['"](?<name>.*)['"]\s+do)/)[:name],
line_number: best_result[:line_number]
}]
else
[{
file: grep_results.first[:file]
}]
end
end
|