Class: TestLauncher::Queries::LineNumberQuery

Inherits:
BaseQuery
  • Object
show all
Defined in:
lib/test_launcher/queries.rb

Constant Summary collapse

LINE_SPLIT_REGEX =
/\A(?<file>.*):(?<line_number>\d+)\Z/

Instance Attribute Summary

Attributes inherited from BaseQuery

#request

Instance Method Summary collapse

Methods inherited from BaseQuery

#initialize

Constructor Details

This class inherits a constructor from TestLauncher::Queries::BaseQuery

Instance Method Details

#commandObject



355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/test_launcher/queries.rb', line 355

def command
  return unless match
  return unless test_cases.any?

  if one_file?
    shell.notify "Found #{pluralize(file_count, "file")}."
    runner.(test_cases.first)
  else
    shell.notify "Found #{pluralize(file_count, "file")}."
    shell.notify "Cannot run all tests with --all because test frameworks don't accept multiple file/lines combos."
    runner.(most_recently_edited_test_case)
  end
end

#matchObject



390
391
392
# File 'lib/test_launcher/queries.rb', line 390

def match
  @match ||= request.search_string.match(LINE_SPLIT_REGEX)
end

#search_resultsObject



380
381
382
383
384
385
386
387
388
# File 'lib/test_launcher/queries.rb', line 380

def search_results
  @search_results ||= begin
    if match
      searcher.(match[:file], match[:line_number].to_i)
    else
      []
    end
  end
end

#test_casesObject



369
370
371
372
373
374
375
376
377
378
# File 'lib/test_launcher/queries.rb', line 369

def test_cases
  @test_cases ||= search_results.map {|sr|
    request.test_case(
      file: sr[:file],
      line_number: sr[:line_number],
      example: sr[:example_name],
      request: request
    )
  }
end