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



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/test_launcher/queries.rb', line 398

def command
  return unless match
  return unless test_cases.any?

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

#matchObject



439
440
441
# File 'lib/test_launcher/queries.rb', line 439

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

#search_resultsObject



429
430
431
432
433
434
435
436
437
# File 'lib/test_launcher/queries.rb', line 429

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

#test_casesObject



418
419
420
421
422
423
424
425
426
427
# File 'lib/test_launcher/queries.rb', line 418

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