Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #166: Silent failure after re-evaluating Guardfile.

  • Loading branch information...
commit caaada69e9065371bbff8ef2f74d5fea493962c6 1 parent ed21c0c
Rémy Coutable rymai authored
10 lib/guard.rb
View
@@ -58,7 +58,7 @@ def setup(options = {})
@options = options
@guards = []
- @groups = [Group.new(:default)]
+ self.reset_groups
@interactor = Interactor.new unless @options[:no_interactions]
@listener = Listener.select_and_init(@options[:watchdir] ? File.expand_path(@options[:watchdir]) : Dir.pwd, options)
@@ -119,6 +119,14 @@ def groups(filter = nil)
end
end
+ # Initialize the groups array with the `:default` group.
+ #
+ # @see Guard.groups
+ #
+ def reset_groups
+ @groups = [Group.new(:default)]
+ end
+
# Start Guard by evaluate the `Guardfile`, initialize the declared Guards
# and start the available file change listener.
#
2  lib/guard/dsl.rb
View
@@ -101,7 +101,7 @@ def evaluate_guardfile(options = {})
#
def reevaluate_guardfile
::Guard.guards.clear
- ::Guard.groups.clear
+ ::Guard.reset_groups
@@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
msg = 'Guardfile has been re-evaluated.'
19 spec/guard/dsl_spec.rb
View
@@ -155,14 +155,31 @@ def self.disable_user_config
describe ".reevaluate_guardfile" do
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
- it "resets already definded guards before calling evaluate_guardfile" do
+ it "resets already defined guards before calling evaluate_guardfile" do
Guard::Notifier.turn_off
described_class.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string)
+
::Guard.guards.should_not be_empty
::Guard::Dsl.should_receive(:evaluate_guardfile)
+
described_class.reevaluate_guardfile
+
::Guard.guards.should be_empty
end
+
+ it "resets groups before calling evaluate_guardfile" do
+ Guard::Notifier.turn_off
+ described_class.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string)
+
+ ::Guard.groups.should_not be_empty
+ ::Guard::Dsl.should_receive(:evaluate_guardfile)
+
+ described_class.reevaluate_guardfile
+
+ ::Guard.groups.should_not be_empty
+ ::Guard.groups[0].name.should eql :default
+ ::Guard.groups[0].options.should == {}
+ end
end
describe ".guardfile_default_path" do
23 spec/guard_spec.rb
View
@@ -58,8 +58,8 @@ class Guard::TestGuard < Guard::Guard
end
it "initializes @groups" do
- described_class.groups[0].name.should eql :default
- described_class.groups[0].options.should == {}
+ subject.groups[0].name.should eql :default
+ subject.groups[0].options.should == {}
end
it "initializes the options" do
@@ -222,6 +222,25 @@ class Guard::FooBaz < Guard::Guard; end
end
end
+ describe ".reset_groups" do
+ subject do
+ guard = ::Guard.setup
+ @group_backend = guard.add_group(:backend)
+ @group_backflip = guard.add_group(:backflip)
+ guard
+ end
+
+ it "return @groups without any argument" do
+ subject.groups.should have(3).items
+
+ subject.reset_groups
+
+ subject.groups.should have(1).item
+ subject.groups[0].name.should eql :default
+ subject.groups[0].options.should == {}
+ end
+ end
+
describe ".start" do
it "basic check that core methods are called" do
opts = { :my_opts => true, :guardfile => File.join(@fixture_path, "Guardfile") }
Please sign in to comment.
Something went wrong with that request. Please try again.