Skip to content

Commit

Permalink
Revert silent discard of NoMethodError from plugins introduced by 95d…
Browse files Browse the repository at this point in the history
…9cd1 (fixes #413)

Rather than silently discarding all NoMethodErrors, we just check
whether the plugin implements the task and only execute it if it does.
  • Loading branch information
Adam Spiers committed Apr 4, 2013
1 parent 2a32757 commit b5a2f01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/guard/runner.rb
Expand Up @@ -51,7 +51,7 @@ def deprecation_warning
def run(task, scopes = {}) def run(task, scopes = {})
Lumberjack.unit_of_work do Lumberjack.unit_of_work do
scoped_guards(scopes) do |guard| scoped_guards(scopes) do |guard|
run_supervised_task(guard, task) run_supervised_task(guard, task) if guard.respond_to?(task)
end end
end end
end end
Expand Down Expand Up @@ -101,8 +101,6 @@ def run_supervised_task(guard, task, *args)
result result
end end


rescue NoMethodError
# Do nothing
rescue Exception => ex rescue Exception => ex
::Guard::UI.error("#{ guard.class.name } failed to achieve its <#{ task.to_s }>, exception was:" + ::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") }") "\n#{ ex.class }: #{ ex.message }\n#{ ex.backtrace.join("\n") }")
Expand Down
7 changes: 5 additions & 2 deletions spec/guard/runner_spec.rb
Expand Up @@ -68,8 +68,9 @@
describe '#run' do describe '#run' do
let(:scopes) { { :group => foo_group } } let(:scopes) { { :group => foo_group } }


it 'executes a supervised task on all registered guards' do it 'executes a supervised task on all registered guards implementing that task' do
[foo_guard, bar1_guard, bar2_guard].each do |g| [foo_guard, bar1_guard].each do |g|
g.stub(:my_task)
subject.should_receive(:run_supervised_task).with(g, :my_task) subject.should_receive(:run_supervised_task).with(g, :my_task)
end end
subject.run(:my_task) subject.run(:my_task)
Expand All @@ -94,6 +95,7 @@
let(:scopes) { { :plugins => [bar1_guard] } } let(:scopes) { { :plugins => [bar1_guard] } }


it 'executes the supervised task on the specified guard only' do 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_receive(:run_supervised_task).with(bar1_guard, :my_task)


subject.should_not_receive(:run_supervised_task).with(foo_guard, :my_task) subject.should_not_receive(:run_supervised_task).with(foo_guard, :my_task)
Expand All @@ -107,6 +109,7 @@
let(:scopes) { { :groups => [foo_group] } } let(:scopes) { { :groups => [foo_group] } }


it 'executes the task on each guard in the specified group only' do 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_receive(:run_supervised_task).with(foo_guard, :my_task)


subject.should_not_receive(:run_supervised_task).with(bar1_guard, :my_task) subject.should_not_receive(:run_supervised_task).with(bar1_guard, :my_task)
Expand Down

1 comment on commit b5a2f01

@amiel
Copy link
Contributor

@amiel amiel commented on b5a2f01 Apr 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.