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
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
Interactor.init_signal_traps
@ -63,14 +63,12 @@ module Guard
# Let a guard execute his task but
# fire it if his work lead to system failure
def supervised_task(guard, task_to_supervise, *args)
begin
guard.send(task_to_supervise, *args)
rescue Exception
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
::Guard.guards.delete guard
UI.info("Guard #{guard.class.name} has just been fired")
return $!
end
guard.send(task_to_supervise, *args)
rescue Exception
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
::Guard.guards.delete guard
UI.info("Guard #{guard.class.name} has just been fired")
return $!
end
def locate_guard(name)

View File

@ -38,25 +38,25 @@ describe Guard do
subject { ::Guard.init }
it "Should retrieve itself for chaining" do
subject.should be_kind_of Module
subject.should be_kind_of(Module)
end
it "Should init guards array" do
::Guard.guards.should be_kind_of Array
::Guard.guards.should be_kind_of(Array)
end
it "Should init options" do
opts = {:my_opts => true}
::Guard.init(opts).options.should be_include :my_opts
::Guard.init(opts).options.should be_include(:my_opts)
end
it "Should init listeners" do
::Guard.listener.should be_kind_of Guard::Listener
::Guard.listener.should be_kind_of(Guard::Listener)
end
end
describe "supervised_task" do
subject {::Guard.init}
subject { ::Guard.init }
before :each do
@g = mock(Guard::Guard)
@ -68,28 +68,28 @@ describe Guard do
end
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.guards.should be_include @g
subject.guards.should be_include(@g)
end
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.guards.should be_include @g
subject.guards.should be_include(@g)
end
it "should fire the guard on spy act discovery" do
subject.guards.should be_include @g
::Guard.supervised_task(@g, :spy).should be_kind_of Exception
subject.guards.should_not be_include @g
subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :spy).should be_kind_of(Exception)
subject.guards.should_not be_include(@g)
::Guard.supervised_task(@g, :spy).message.should == 'I break your system'
end
it "should fire the guard on pirate act discovery" do
subject.guards.should be_include @g
::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 be_kind_of(String)
subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :regular_arg, "given_path").should == "given_path"
end
end