Class: TestLauncher::Queries::MultiExampleNameQuery

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

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



263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/test_launcher/queries.rb', line 263

def command
  return if test_cases.empty?

  if one_example?
    shell.notify("Found 1 example in 1 file.")
    runner.single_example(test_cases.first)
  elsif one_file?
    shell.notify("Found #{test_cases.size} examples in 1 file.")
    runner.multiple_examples_same_file(test_cases) # it will regex with the query
  else
    shell.notify "Found #{pluralize(test_cases.size, "example")} in #{pluralize(file_count, "file")}."
    runner.multiple_examples(test_cases)
  end
end

#examples_foundObject



291
292
293
# File 'lib/test_launcher/queries.rb', line 291

def examples_found
  @examples_found_by_joining_query ||= searcher.examples(joined_query)
end

#joined_queryObject



295
296
297
# File 'lib/test_launcher/queries.rb', line 295

def joined_query
  @joined_query ||= request.search_string.squeeze(" ").gsub(" ", "|")
end

#one_example?Boolean

Returns:

  • (Boolean)


299
300
301
# File 'lib/test_launcher/queries.rb', line 299

def one_example?
  test_cases.size == 1
end

#test_casesObject



278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/test_launcher/queries.rb', line 278

def test_cases
  return [] if joined_query == request.search_string

  @test_cases_found_by_joining_query ||= examples_found.map { |grep_result|
    request.test_case(
      file: grep_result[:file],
      example: joined_query,
      line_number: grep_result[:line_number],
      request: request
    )
  }
end