Class: TestLauncher::Frameworks::Implementation::Consolidator

Inherits:
Struct
  • Object
show all
Defined in:
lib/test_launcher/frameworks/implementation/consolidator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#run_allObject

Returns the value of attribute run_all

Returns:

  • (Object)

    the current value of run_all



4
5
6
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 4

def run_all
  @run_all
end

#runnerObject

Returns the value of attribute runner

Returns:

  • (Object)

    the current value of runner



4
5
6
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 4

def runner
  @runner
end

#search_resultsObject

Returns the value of attribute search_results

Returns:

  • (Object)

    the current value of search_results



4
5
6
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 4

def search_results
  @search_results
end

#shellObject

Returns the value of attribute shell

Returns:

  • (Object)

    the current value of shell



4
5
6
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 4

def shell
  @shell
end

Class Method Details

.consolidate(*args) ⇒ Object



6
7
8
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 6

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

Instance Method Details

#consolidateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 10

def consolidate
  if search_results.empty?
    nil
  elsif one_example?
    shell.notify "Found #{methods_count_phrase} in #{file_count_phrase}."
    runner.single_example(search_results.first)
  elsif examples_found? && same_file?
    shell.notify "Multiple test methods match in 1 file."
    runner.single_example(search_results.first)
  elsif examples_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."
    runner.single_example(last_edited)
  elsif files_found? && same_file?
    shell.notify "Found #{file_count_phrase}."
    runner.single_file(search_results.first)
  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."
    runner.single_file(last_edited)
  else
    shell.notify "Found #{file_count_phrase}."
    runner.multiple_files(search_results.uniq {|sr| sr.file})
  end
end

#examples_found?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 44

def examples_found?
  search_results.examples_found?
end

#file_countObject



60
61
62
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 60

def file_count
  search_results.file_count
end

#file_count_phraseObject



68
69
70
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 68

def file_count_phrase
  pluralize(file_count, "file")
end

#files_found?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 48

def files_found?
  ! examples_found?
end

#last_editedObject



56
57
58
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 56

def last_edited
  search_results.last_edited
end

#methods_count_phraseObject



64
65
66
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 64

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

#one_example?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 40

def one_example?
  search_results.one_example?
end

#pluralize(count, singular) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 72

def pluralize(count, singular)
  phrase = "#{count} #{singular}"
  if count == 1
    phrase
  else
    "#{phrase}s"
  end
end

#run_last_edited?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 52

def run_last_edited?
  ! run_all
end

#same_file?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/test_launcher/frameworks/implementation/consolidator.rb', line 36

def same_file?
  file_count == 1
end