Skip to content

Commit

Permalink
Merge afa2fb4 into 6649685
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Nov 1, 2014
2 parents 6649685 + afa2fb4 commit b80095c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/guard/plugin_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def initialize_plugin(options)
if klass.superclass.to_s == "Guard::Guard"
klass.new(options.delete(:watchers), options)
else
klass.new(options)
begin
klass.new(options)
rescue ArgumentError => e
fail "Failed to call #{klass}.new(options): #{e}"
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/guard/reevaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def run_on_modifications(files)
return unless ::Guard::Watcher.match_guardfile?(files)
::Guard.save_scope
::Guard.evaluator.reevaluate_guardfile
rescue ScriptError, StandardError => e
::Guard::UI.warning("Failed to reevaluate file: #{e}")
ensure
::Guard.restore_scope
end
end
Expand Down
42 changes: 41 additions & 1 deletion spec/lib/guard/reevaluator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "guard/plugin"

require "guard/reevaluator.rb"
require "guard/ui"

describe Guard::Reevaluator do
let(:options) { {} }
Expand All @@ -27,9 +28,48 @@
expect(evaluator).to receive(:reevaluate_guardfile)
subject.run_on_modifications(["Guardfile"])
end

context "when Guardfile contains errors" do
let(:failure) { proc { fail RuntimeError, "Could not load Foo!" } }

before do
allow(evaluator).to receive(:reevaluate_guardfile) { failure.call }
end

context "with a name error" do
let(:failure) { proc { fail NameError, "Could not load Foo!" } }
it "should not raise error to prevent being fired" do
expect { subject.run_on_modifications(["Guardfile"]) }.
to_not raise_error
end
end

context "with a syntax error" do
let(:failure) { proc { fail SyntaxError, "Could not load Foo!" } }
it "should not raise error to prevent being fired" do
expect { subject.run_on_modifications(["Guardfile"]) }.
to_not raise_error
end
end

# TODO: show backtrace?
it "should show warning about the error" do
expect(::Guard::UI).to receive(:warning).
with("Failed to reevaluate file: Could not load Foo!")

subject.run_on_modifications(["Guardfile"])
end

it "should restore the scope" do
expect(::Guard).to receive(:restore_scope)

subject.run_on_modifications(["Guardfile"])
end
end

end

context "when Guardfile is modified" do
context "when Guardfile is not modified" do
before do
allow(::Guard::Watcher).to receive(:match_guardfile?).with(["foo"]).
and_return(false)
Expand Down

0 comments on commit b80095c

Please sign in to comment.