diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index f5247eb..9568631 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -1,29 +1,41 @@ module Guard module Interactor - + extend self + + def run_all + ::Guard.run do + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } + end + end + + def stop + UI.info "Bye bye...", :reset => true + ::Guard.listener.stop + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } + abort("\n") + end + + def reload + ::Guard.run do + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } + end + end + def self.init_signal_traps # Run all (Ctrl-\) Signal.trap('QUIT') do - ::Guard.run do - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } - end + run_all end - + # Stop (Ctrl-C) Signal.trap('INT') do - UI.info "Bye bye...", :reset => true - ::Guard.listener.stop - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } - abort("\n") + stop end - + # Reload (Ctrl-Z) Signal.trap('TSTP') do - ::Guard.run do - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } - end + reload end end - end -end \ No newline at end of file +end diff --git a/spec/guard/interactor_spec.rb b/spec/guard/interactor_spec.rb new file mode 100644 index 0000000..6471f52 --- /dev/null +++ b/spec/guard/interactor_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Guard::Interactor do + subject { Guard::Interactor } + let(:guard) { mock "guard" } + before :each do + Guard.stub!(:guards).and_return([guard]) + Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil)) + end + + it ".run_all should send :run_all to all guards" do + guard.should_receive(:run_all) + subject.run_all + end + + it ".stop should send :stop to all guards" do + guard.should_receive(:stop) + lambda { subject.stop }.should raise_error(SystemExit) + end + + it ".reload should send :reload to all guards" do + guard.should_receive(:reload) + subject.reload + end +end