Actually halt guards' execution in a group only when the guard's task throw :task_has_failed (not when it returns false).
This commit is contained in:
parent
b1b69924a7
commit
078d55f13c
11
lib/guard.rb
11
lib/guard.rb
@ -96,7 +96,7 @@ module Guard
|
||||
|
||||
def execute_supervised_task_for_all_guards(task, files = nil)
|
||||
groups.each do |group_hash|
|
||||
catch :task_has_failed do
|
||||
catch group_hash[:options][:halt_on_fail] == true ? :task_has_failed : nil do
|
||||
guards.find_all { |guard| guard.group == group_hash[:name] }.each do |guard|
|
||||
paths = Watcher.match_files(guard, files) if files
|
||||
if paths && !paths.empty?
|
||||
@ -116,14 +116,7 @@ module Guard
|
||||
guard.hook("#{task_to_supervise}_begin", *args)
|
||||
result = guard.send(task_to_supervise, *args)
|
||||
guard.hook("#{task_to_supervise}_end", result)
|
||||
|
||||
group = @groups.find { |group| group[:name] == guard.group }
|
||||
if result === false && group[:options][:halt_on_fail] == true
|
||||
UI.error "#{guard.class.name}##{task_to_supervise} failed."
|
||||
throw :task_has_failed
|
||||
else
|
||||
result
|
||||
end
|
||||
result
|
||||
|
||||
rescue Exception => ex
|
||||
UI.error("#{guard.class.name} failed to achieve its <#{task_to_supervise.to_s}>, exception was:" +
|
||||
|
@ -255,7 +255,16 @@ describe Guard do
|
||||
|
||||
context "one guard fails (by returning false)" do
|
||||
before do
|
||||
subject.guards.each_with_index { |g, i| g.stub!(:task) { @sum[g.group] += i+1; i != 0 && i != 2 } }
|
||||
subject.guards.each_with_index do |g, i|
|
||||
g.stub!(:task) do
|
||||
@sum[g.group] += i+1
|
||||
if i % 2 == 0
|
||||
throw :task_has_failed
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "executes the task only for guards that didn't fail for group with :halt_on_fail == true" do
|
||||
@ -324,7 +333,7 @@ describe Guard do
|
||||
end
|
||||
|
||||
context "with a task that return false and guard's group has the :halt_on_fail option == true" do
|
||||
before(:each) { @g.stub!(:group) { :foo }; @g.stub!(:failing) { false } }
|
||||
before(:each) { @g.stub!(:group) { :foo }; @g.stub!(:failing) { throw :task_has_failed } }
|
||||
|
||||
it "throws :task_has_failed" do
|
||||
expect { subject.supervised_task(@g, :failing) }.to throw_symbol(:task_has_failed)
|
||||
|
Loading…
Reference in New Issue
Block a user