Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow user-based Guardfiles

  • Loading branch information...
commit debdecbbd726eb7f6d24d9147a1933efb97a4d5c 1 parent ce2a5c5
Joshua Davey and Veezus Kreist authored Hashrocket Workstation committed
Showing with 42 additions and 6 deletions.
  1. +12 −2 lib/guard/dsl.rb
  2. +30 −4 spec/guard/dsl_spec.rb
View
14 lib/guard/dsl.rb
@@ -13,7 +13,7 @@ def evaluate_guardfile(options = {})
exit 1
end
else
- UI.error "No Guardfile in current folder, please create one."
+ UI.error "No Guardfile found, please create one."
exit 1
end
end
@@ -23,7 +23,17 @@ def guardfile_include?(guard_name)
end
def guardfile_path
- File.join(Dir.pwd, 'Guardfile')
+ return local_guardfile_path if File.exist? local_guardfile_path
+ home_guardfile_path
+ end
+
+ private
+ def local_guardfile_path
+ File.join(Dir.pwd, "Guardfile")
+ end
+
+ def home_guardfile_path
+ File.join(ENV['HOME'], "Guardfile")
end
end
View
34 spec/guard/dsl_spec.rb
@@ -8,9 +8,8 @@
end
it "displays an error message when no Guardfile is found" do
- Dir.stub!(:pwd).and_return("no_guardfile_here")
-
- Guard::UI.should_receive(:error).with("No Guardfile in current folder, please create one.")
+ subject.stub(:guardfile_path).and_return("no_guardfile_here")
+ Guard::UI.should_receive(:error).with("No Guardfile found, please create one.")
lambda { subject.evaluate_guardfile }.should raise_error
end
@@ -21,6 +20,33 @@
lambda { subject.evaluate_guardfile }.should raise_error
end
+ describe ".guardfile_path" do
+ let(:local_path) { File.join(Dir.pwd, 'Guardfile') }
+ let(:user_path) { File.join(ENV["HOME"], 'Guardfile') }
+ before do
+ File.stub(:exist? => false)
+ end
+ context "when there is a local Guardfile" do
+ it "returns the path to the local Guardfile" do
+ File.stub(:exist?).with(local_path).and_return(true)
+ subject.guardfile_path.should == local_path
+ end
+ end
+ context "when there is a Guardfile in the user's home directory" do
+ it "returns the path to the user Guardfile" do
+ File.stub(:exist?).with(user_path).and_return(true)
+ subject.guardfile_path.should == user_path
+ end
+ end
+ context "when there's both a local and user Guardfile" do
+ it "returns the path to the local Guardfile" do
+ File.stub(:exist?).with(local_path).and_return(true)
+ File.stub(:exist?).with(user_path).and_return(true)
+ subject.guardfile_path.should == local_path
+ end
+ end
+ end
+
describe ".guardfile_include?" do
it "detects a Guard specified by a string with simple quotes" do
mock_guardfile_content("guard 'test'")
@@ -117,7 +143,7 @@
private
def mock_guardfile_content(content)
- File.stub!(:read).with(File.expand_path('../../../Guardfile', __FILE__)) { content }
+ File.stub!(:read).with(subject.guardfile_path) { content }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.