class TestRun::Tests::Minitest::Consolidator

Public Class Methods

consolidate(*args) click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 14
def self.consolidate(*args)
  new(*args).consolidate
end

Public Instance Methods

consolidate() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 18
def consolidate
  if search_results.empty?
    shell.warn "Could not find any tests."
    exit
  end

  if methods_found? && one_result?
    shell.notify "Found #{methods_count_phrase} in #{file_count_phrase}."
    Wrappers::SingleTest.new(search_results.first)
  elsif methods_found? && same_file?
    shell.notify "Multiple test methods match in 1 file."
    Wrappers::SingleFile.new(search_results.first[:file])
  elsif methods_found? && run_last_edited?
    shell.notify "Found #{methods_count_phrase} in #{file_count_phrase}."
    shell.notify "Running most recently edited. Run with '--all' to run all the tests."
    Wrappers::SingleTest.new(last_edited)
  elsif files_found? && same_file?
    shell.notify "Found #{file_count_phrase}."
    Wrappers::SingleFile.new(search_results.first[:file])
  elsif files_found? && run_last_edited?
    shell.notify "Found #{file_count_phrase}."
    shell.notify "Running most recently edited. Run with '--all' to run all the tests."
    Wrappers::SingleFile.new(last_edited[:file])
  else
    shell.notify "Found #{file_count_phrase}."
    Wrappers::MultipleFiles.wrap(search_results.map {|r| r[:file] }, shell)
  end
end
file_count() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 71
def file_count
  search_results.group_by {|f| f[:file]}.size
end
file_count_phrase() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 79
def file_count_phrase
  pluralize(file_count, "file")
end
files_found?() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 59
def files_found?
  ! methods_found?
end
last_edited() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 67
def last_edited
  search_results.sort_by {|r| File.mtime(r[:file])}.last
end
methods_count_phrase() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 75
def methods_count_phrase
  pluralize(search_results.size, "test method")
end
methods_found?() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 55
def methods_found?
  !! search_results.first[:line]
end
one_result?() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 51
def one_result?
  same_file? && search_results.first[:line]
end
run_last_edited?() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 63
def run_last_edited?
  ! run_all
end
same_file?() click to toggle source
# File lib/test_run/tests/minitest/consolidator.rb, line 47
def same_file?
   file_count == 1
end