Skip to content

Commit

Permalink
Merge pull request #939 from guard/937-do-not-swallow-guardfile-evalu…
Browse files Browse the repository at this point in the history
…ation-errors

Don't swallow evaluator error by handling non-existant listener & interactor
  • Loading branch information
rymai committed Nov 1, 2019
2 parents a9cbc40 + c1ad9ee commit 7b9bb18
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inherit_from:

# Files you want to exclude
AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.3
Exclude:
- vendor/**/*
- db/schema.rb
Expand Down
4 changes: 2 additions & 2 deletions lib/guard/commander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def start(options = {})
end

def stop
listener.stop
interactor.background
listener&.stop
interactor&.background
UI.debug "Guard stops all plugins"
Runner.new.run(:stop)
Notifier.disconnect
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/guard/commander_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@
expect { Guard.start }.to raise_error(RuntimeError)
end
end

context "when setup raises an error" do
it "calls Commander#stop" do
# Reproduce a case where an error is raised during Guardfile evaluation
# before the listener and interactor are instantiated.
expect(Guard).to receive(:listener).and_return(nil)
expect(Guard).to receive(:interactor).and_return(nil)
expect(Guard).to receive(:setup).and_raise(RuntimeError)

# From stop()
expect(runner).to receive(:run).with(:stop)
expect(Guard::UI).to receive(:info).with("Bye bye...", reset: true)

expect { Guard.start }.to raise_error(RuntimeError)
end
end
end

describe ".stop" do
Expand Down

0 comments on commit 7b9bb18

Please sign in to comment.