From b5a2f01ed49d488a46be3d5ed5425caf539ef6cb Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 4 Apr 2013 13:32:24 +0100 Subject: [PATCH] Revert silent discard of NoMethodError from plugins introduced by 95d9cd1b (fixes #413) Rather than silently discarding all NoMethodErrors, we just check whether the plugin implements the task and only execute it if it does. --- lib/guard/runner.rb | 4 +--- spec/guard/runner_spec.rb | 7 +++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/guard/runner.rb b/lib/guard/runner.rb index ce8402950..e611e19be 100644 --- a/lib/guard/runner.rb +++ b/lib/guard/runner.rb @@ -51,7 +51,7 @@ def deprecation_warning def run(task, scopes = {}) Lumberjack.unit_of_work do scoped_guards(scopes) do |guard| - run_supervised_task(guard, task) + run_supervised_task(guard, task) if guard.respond_to?(task) end end end @@ -101,8 +101,6 @@ def run_supervised_task(guard, task, *args) result end - rescue NoMethodError - # Do nothing rescue Exception => ex ::Guard::UI.error("#{ guard.class.name } failed to achieve its <#{ task.to_s }>, exception was:" + "\n#{ ex.class }: #{ ex.message }\n#{ ex.backtrace.join("\n") }") diff --git a/spec/guard/runner_spec.rb b/spec/guard/runner_spec.rb index f4aa0d0c7..2979899b4 100644 --- a/spec/guard/runner_spec.rb +++ b/spec/guard/runner_spec.rb @@ -68,8 +68,9 @@ describe '#run' do let(:scopes) { { :group => foo_group } } - it 'executes a supervised task on all registered guards' do - [foo_guard, bar1_guard, bar2_guard].each do |g| + it 'executes a supervised task on all registered guards implementing that task' do + [foo_guard, bar1_guard].each do |g| + g.stub(:my_task) subject.should_receive(:run_supervised_task).with(g, :my_task) end subject.run(:my_task) @@ -94,6 +95,7 @@ let(:scopes) { { :plugins => [bar1_guard] } } it 'executes the supervised task on the specified guard only' do + bar1_guard.stub(:my_task) subject.should_receive(:run_supervised_task).with(bar1_guard, :my_task) subject.should_not_receive(:run_supervised_task).with(foo_guard, :my_task) @@ -107,6 +109,7 @@ let(:scopes) { { :groups => [foo_group] } } it 'executes the task on each guard in the specified group only' do + foo_guard.stub(:my_task) subject.should_receive(:run_supervised_task).with(foo_guard, :my_task) subject.should_not_receive(:run_supervised_task).with(bar1_guard, :my_task)