Skip to content

Commit

Permalink
Fixes pull-request guard#214 properly ("ERROR: No guards found in Gua…
Browse files Browse the repository at this point in the history
…rdfile" message wrongly displayed when running `guard list`).
  • Loading branch information
rymai committed Jan 2, 2012
1 parent 9094f59 commit 3b56ef7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## Master

### Bug fix

- [#213 & 214](https://github.com/guard/guard/issues/214): Fixes the "ERROR: No guards found in Guardfile" message wrongly displayed when running `guard list`. ([@pirukire][])

## 0.10.0 - 1 January, 2012

### Improvement
Expand Down Expand Up @@ -410,6 +416,7 @@
[@niklas]: https://github.com/niklas
[@oliamb]: https://github.com/oliamb
[@pcreux]: https://github.com/pcreux
[@pirukire]: https://github.com/pirukire
[@rmm5t]: https://github.com/rmm5t
[@rymai]: https://github.com/rymai
[@scottdavis]: https://github.com/scottdavis
Expand Down
1 change: 1 addition & 0 deletions lib/guard.rb
Expand Up @@ -180,6 +180,7 @@ def start(options = {})
setup(options)

Dsl.evaluate_guardfile(options)
UI.error 'No guards found in Guardfile, please add at least one.' if ::Guard.guards.empty?

options[:notify] && ENV['GUARD_NOTIFY'] != 'false' ? Notifier.turn_on : Notifier.turn_off

Expand Down
3 changes: 1 addition & 2 deletions lib/guard/dsl.rb
Expand Up @@ -100,8 +100,6 @@ def evaluate_guardfile(options = {})

fetch_guardfile_contents
instance_eval_guardfile(guardfile_contents_with_user_config)

UI.error 'No guards found in Guardfile, please add at least one.' if ::Guard.guards.nil? && ::Guard.guards.empty?
end

# Re-evaluate the `Guardfile` to update the current Guard configuration.
Expand All @@ -117,6 +115,7 @@ def reevaluate_guardfile
::Guard::Notifier.clear_notifications
@@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
UI.error 'No guards found in Guardfile, please add at least one.' if ::Guard.guards.empty?
msg = 'Guardfile has been re-evaluated.'
UI.info(msg)
Notifier.notify(msg)
Expand Down
6 changes: 3 additions & 3 deletions spec/guard/dsl_describer_spec.rb
Expand Up @@ -6,7 +6,7 @@

let(:guardfile) do
<<-GUARD
guard 'test', :a => :b do
guard :test, :a => :b do
watch('c')
end
Expand All @@ -17,7 +17,7 @@
end
group "b" do
guard 'another' do
guard :another do
watch('c')
end
end
Expand All @@ -34,7 +34,7 @@
end

describe '.list' do
it 'lists the available Guards' do
it "lists the available Guards when they're declared as strings or symbols" do
Guard.stub(:guard_gem_names).and_return ['test', 'another', 'even', 'more']
describer.list(:guardfile_contents => guardfile)
@output.should eql <<OUTPUT
Expand Down
6 changes: 3 additions & 3 deletions spec/guard/dsl_spec.rb
Expand Up @@ -78,10 +78,10 @@ def self.disable_user_config
lambda { described_class.evaluate_guardfile }.should raise_error
end

it "displays an error message when no guard are defined in Guardfile" do
it "doesn't display an error message when no guard are defined in Guardfile" do
::Guard::Dsl.stub!(:instance_eval_guardfile)
::Guard.stub!(:guards).and_return([])
Guard::UI.should_receive(:error)
Guard::UI.should_not_receive(:error)
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
end

Expand Down Expand Up @@ -190,7 +190,7 @@ def self.disable_user_config
described_class.reevaluate_guardfile

::Guard.groups.should_not be_empty
::Guard.groups[0].name.should eql :default
::Guard.groups[0].name.should eq :default
::Guard.groups[0].options.should == {}
end

Expand Down
6 changes: 6 additions & 0 deletions spec/guard_spec.rb
Expand Up @@ -265,6 +265,12 @@ class Guard::FooBaz < Guard::Guard; end
::Guard.start(options)
end

it "displays an error message when no guard are defined in Guardfile" do
::Guard::Dsl.should_receive(:evaluate_guardfile).with(options)
::Guard::UI.should_receive(:error)
::Guard.start(options)
end

it "starts the listeners" do
::Guard.listener.should_receive(:start)
::Guard.start(options)
Expand Down

0 comments on commit 3b56ef7

Please sign in to comment.