Little "refactoring"

This commit is contained in:
Thibaud Guillaume-Gentil 2010-10-28 08:47:26 +02:00
parent 01bf7505cd
commit 9c15536eda
2 changed files with 22 additions and 24 deletions

View File

@ -25,7 +25,7 @@ module Guard
Dsl.evaluate_guardfile Dsl.evaluate_guardfile
if guards.empty? if guards.empty?
UI.error "No guards found in Guardfile, please add it at least one." UI.error "No guards found in Guardfile, please add at least one."
else else
Interactor.init_signal_traps Interactor.init_signal_traps
@ -63,7 +63,6 @@ module Guard
# Let a guard execute his task but # Let a guard execute his task but
# fire it if his work lead to system failure # fire it if his work lead to system failure
def supervised_task(guard, task_to_supervise, *args) def supervised_task(guard, task_to_supervise, *args)
begin
guard.send(task_to_supervise, *args) guard.send(task_to_supervise, *args)
rescue Exception rescue Exception
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}") UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
@ -71,7 +70,6 @@ module Guard
UI.info("Guard #{guard.class.name} has just been fired") UI.info("Guard #{guard.class.name} has just been fired")
return $! return $!
end end
end
def locate_guard(name) def locate_guard(name)
`gem open guard-#{name} --latest --command echo`.chomp `gem open guard-#{name} --latest --command echo`.chomp

View File

@ -38,20 +38,20 @@ describe Guard do
subject { ::Guard.init } subject { ::Guard.init }
it "Should retrieve itself for chaining" do it "Should retrieve itself for chaining" do
subject.should be_kind_of Module subject.should be_kind_of(Module)
end end
it "Should init guards array" do it "Should init guards array" do
::Guard.guards.should be_kind_of Array ::Guard.guards.should be_kind_of(Array)
end end
it "Should init options" do it "Should init options" do
opts = {:my_opts => true} opts = {:my_opts => true}
::Guard.init(opts).options.should be_include :my_opts ::Guard.init(opts).options.should be_include(:my_opts)
end end
it "Should init listeners" do it "Should init listeners" do
::Guard.listener.should be_kind_of Guard::Listener ::Guard.listener.should be_kind_of(Guard::Listener)
end end
end end
@ -68,28 +68,28 @@ describe Guard do
end end
it "should let it go when nothing special occurs" do it "should let it go when nothing special occurs" do
subject.guards.should be_include @g subject.guards.should be_include(@g)
subject.supervised_task(@g, :regular).should be_true subject.supervised_task(@g, :regular).should be_true
subject.guards.should be_include @g subject.guards.should be_include(@g)
end end
it "should let it work with some tools" do it "should let it work with some tools" do
subject.guards.should be_include @g subject.guards.should be_include(@g)
subject.supervised_task(@g, :regular).should be_true subject.supervised_task(@g, :regular).should be_true
subject.guards.should be_include @g subject.guards.should be_include(@g)
end end
it "should fire the guard on spy act discovery" do it "should fire the guard on spy act discovery" do
subject.guards.should be_include @g subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :spy).should be_kind_of Exception ::Guard.supervised_task(@g, :spy).should be_kind_of(Exception)
subject.guards.should_not be_include @g subject.guards.should_not be_include(@g)
::Guard.supervised_task(@g, :spy).message.should == 'I break your system' ::Guard.supervised_task(@g, :spy).message.should == 'I break your system'
end end
it "should fire the guard on pirate act discovery" do it "should fire the guard on pirate act discovery" do
subject.guards.should be_include @g subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :regular_arg, "given_path").should be_kind_of String ::Guard.supervised_task(@g, :regular_arg, "given_path").should be_kind_of(String)
subject.guards.should be_include @g subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :regular_arg, "given_path").should == "given_path" ::Guard.supervised_task(@g, :regular_arg, "given_path").should == "given_path"
end end
end end