class TestLauncher::Frameworks::Mochajs::Searcher
Public Instance Methods
by_line(file_pattern, line_number)
click to toggle source
# File lib/test_launcher/frameworks/mochajs.rb, line 26 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? # the file exists, but doesn't appear to contain any tests... # we'll try to run it anyway 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(/(it|describe)\(["'](.*)['"],/)[2], line_number: best_result[:line_number] }] else # line number outside of example. Run whole file [{ file: grep_results.first[:file] }] end end
Private Instance Methods
example_name_regex(query="")
click to toggle source
# File lib/test_launcher/frameworks/mochajs.rb, line 69 def example_name_regex(query="") "^\s*(it|describe).*(#{query}).*,.*" end
file_name_pattern()
click to toggle source
# File lib/test_launcher/frameworks/mochajs.rb, line 65 def file_name_pattern '*pec.js' end
file_name_regex()
click to toggle source
# File lib/test_launcher/frameworks/mochajs.rb, line 61 def file_name_regex /.*pec\.js/ end