Class: MightyTest::Watcher
- Inherits:
-
Object
- Object
- MightyTest::Watcher
- Defined in:
- lib/mighty_test/watcher.rb,
lib/mighty_test/watcher/event_queue.rb
Defined Under Namespace
Classes: EventQueue
Constant Summary collapse
- WATCHING_FOR_CHANGES =
'Watching for changes to source and test files. Press "h" for help or "q" to quit.'.freeze
Instance Method Summary collapse
-
#initialize(console: Console.new, extra_args: [], event_queue: nil, file_system: nil, system_proc: nil) ⇒ Watcher
constructor
A new instance of Watcher.
- #run ⇒ Object
Constructor Details
#initialize(console: Console.new, extra_args: [], event_queue: nil, file_system: nil, system_proc: nil) ⇒ Watcher
Returns a new instance of Watcher.
7 8 9 10 11 12 13 |
# File 'lib/mighty_test/watcher.rb', line 7 def initialize(console: Console.new, extra_args: [], event_queue: nil, file_system: nil, system_proc: nil) @console = console @extra_args = extra_args @file_system = file_system || FileSystem.new @system_proc = system_proc || method(:system) @event_queue = event_queue || EventQueue.new(console: @console, file_system: @file_system) end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mighty_test/watcher.rb', line 15 def run event_queue.start puts WATCHING_FOR_CHANGES loop do case event_queue.pop in [:file_system_changed, [_, *] => paths] then run_matching_test_files(paths) in [:keypress, "\r" | "\n"] then run_all_tests in [:keypress, "a"] then run_all_tests(flags: ["--all"]) in [:keypress, "d"] then run_matching_test_files_from_git_diff in [:keypress, "h"] then show_help in [:keypress, "q"] then break else nil end end ensure event_queue.stop puts "\nExiting." end |