Class: TestRun::Tests::Minitest::Consolidator

Inherits:
Struct
  • Object
show all
Includes:
Utils::Pluralize
Defined in:
lib/test_run/tests/minitest/consolidator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Pluralize

#pluralize

Instance Attribute Details

#run_allObject

Returns the value of attribute run_all

Returns:

  • (Object)

    the current value of run_all



11
12
13
# File 'lib/test_run/tests/minitest/consolidator.rb', line 11

def run_all
  @run_all
end

#search_resultsObject

Returns the value of attribute search_results

Returns:

  • (Object)

    the current value of search_results



11
12
13
# File 'lib/test_run/tests/minitest/consolidator.rb', line 11

def search_results
  @search_results
end

#shellObject

Returns the value of attribute shell

Returns:

  • (Object)

    the current value of shell



11
12
13
# File 'lib/test_run/tests/minitest/consolidator.rb', line 11

def shell
  @shell
end

Class Method Details

.consolidate(*args) ⇒ Object



14
15
16
# File 'lib/test_run/tests/minitest/consolidator.rb', line 14

def self.consolidate(*args)
  new(*args).consolidate
end

Instance Method Details

#consolidateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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_countObject



71
72
73
# File 'lib/test_run/tests/minitest/consolidator.rb', line 71

def file_count
  search_results.group_by {|f| f[:file]}.size
end

#file_count_phraseObject



79
80
81
# File 'lib/test_run/tests/minitest/consolidator.rb', line 79

def file_count_phrase
  pluralize(file_count, "file")
end

#files_found?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/test_run/tests/minitest/consolidator.rb', line 59

def files_found?
  ! methods_found?
end

#last_editedObject



67
68
69
# 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_phraseObject



75
76
77
# File 'lib/test_run/tests/minitest/consolidator.rb', line 75

def methods_count_phrase
  pluralize(search_results.size, "test method")
end

#methods_found?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/test_run/tests/minitest/consolidator.rb', line 55

def methods_found?
  !! search_results.first[:line]
end

#one_result?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/test_run/tests/minitest/consolidator.rb', line 51

def one_result?
  same_file? && search_results.first[:line]
end

#run_last_edited?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/test_run/tests/minitest/consolidator.rb', line 63

def run_last_edited?
  ! run_all
end

#same_file?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/test_run/tests/minitest/consolidator.rb', line 47

def same_file?
   file_count == 1
end