Class: TestRun::Tests::Minitest::Consolidator
- Inherits:
-
Struct
- Object
- Struct
- TestRun::Tests::Minitest::Consolidator
- Includes:
- Utils::Pluralize
- Defined in:
- lib/test_run/tests/minitest/consolidator.rb
Instance Attribute Summary collapse
-
#run_all ⇒ Object
Returns the value of attribute run_all.
-
#search_results ⇒ Object
Returns the value of attribute search_results.
-
#shell ⇒ Object
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
- #consolidate ⇒ Object
- #file_count ⇒ Object
- #file_count_phrase ⇒ Object
- #files_found? ⇒ Boolean
- #last_edited ⇒ Object
- #methods_count_phrase ⇒ Object
- #methods_found? ⇒ Boolean
- #one_result? ⇒ Boolean
- #run_last_edited? ⇒ Boolean
- #same_file? ⇒ Boolean
Methods included from Utils::Pluralize
Instance Attribute Details
#run_all ⇒ Object
Returns the value of attribute run_all
11 12 13 |
# File 'lib/test_run/tests/minitest/consolidator.rb', line 11 def run_all @run_all end |
#search_results ⇒ Object
Returns the value of attribute search_results
11 12 13 |
# File 'lib/test_run/tests/minitest/consolidator.rb', line 11 def search_results @search_results end |
#shell ⇒ Object
Returns the value of attribute 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
#consolidate ⇒ Object
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_count ⇒ Object
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_phrase ⇒ Object
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
59 60 61 |
# File 'lib/test_run/tests/minitest/consolidator.rb', line 59 def files_found? ! methods_found? end |
#last_edited ⇒ Object
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_phrase ⇒ Object
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
55 56 57 |
# File 'lib/test_run/tests/minitest/consolidator.rb', line 55 def methods_found? !! search_results.first[:line] end |
#one_result? ⇒ 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
63 64 65 |
# File 'lib/test_run/tests/minitest/consolidator.rb', line 63 def run_last_edited? ! run_all end |
#same_file? ⇒ Boolean
47 48 49 |
# File 'lib/test_run/tests/minitest/consolidator.rb', line 47 def same_file? file_count == 1 end |