Permalink
Browse files

Fix `guard init` when a guard name is given

  • Loading branch information...
Rémy Coutable
Rémy Coutable committed Oct 21, 2011
1 parent 04ff50b commit 1059be04c61216cb070c507f71343b3daba8d6a4
Showing with 40 additions and 22 deletions.
  1. +6 −0 CHANGELOG.md
  2. +8 −8 lib/guard.rb
  3. +26 −14 spec/guard_spec.rb
View
@@ -1,3 +1,9 @@
+## 0.8.8 - October 21, 2011
+
+### Bug fix
+
+- Fix `guard init` when a guard name is given. ([@rymai][])
+
## 0.8.7 - October 18, 2011
### Bug fix
View
@@ -29,17 +29,17 @@ class << self
# @param [String] guard_name the name of the Guard to initialize
#
def initialize_template(guard_name = nil)
+ if !File.exist?('Guardfile')
+ ::Guard::UI.info "Writing new Guardfile to #{ Dir.pwd }/Guardfile"
+ FileUtils.cp(GUARDFILE_TEMPLATE, 'Guardfile')
+ elsif guard_name.nil?
+ ::Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile"
+ exit 1
+ end
+
if guard_name
guard_class = ::Guard.get_guard_class(guard_name)
guard_class.init(guard_name)
- else
- if !File.exist?('Guardfile')
- ::Guard::UI.info "Writing new Guardfile to #{ Dir.pwd }/Guardfile"
- FileUtils.cp(GUARDFILE_TEMPLATE, 'Guardfile')
- else
- ::Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile"
- exit 1
- end
end
end
View
@@ -8,39 +8,51 @@
end
describe ".initialize_template" do
+ before { Dir.stub(:pwd).and_return "/home/user" }
+
context "with a Guard name" do
- it "initializes a the Guard" do
- class Guard::TestGuard < Guard::Guard
+ class Guard::Foo < Guard::Guard
+ end
+
+ context "with an existing Guardfile" do
+ before { File.should_receive(:exist?).and_return true }
+
+ it "initializes the Guard" do
+ Guard::Foo.should_receive(:init)
+ Guard.initialize_template('foo')
+ end
+ end
+
+ context "without an existing Guardfile" do
+ before { File.should_receive(:exist?).and_return false }
+
+ it "copies the Guardfile template and initializes the Guard" do
+ ::Guard::UI.should_receive(:info).with("Writing new Guardfile to /home/user/Guardfile")
+ FileUtils.should_receive(:cp).with(an_instance_of(String), 'Guardfile')
+ Guard::Foo.should_receive(:init)
+ Guard.initialize_template('foo')
end
- Guard::TestGuard.should_receive(:init)
- Guard.initialize_template('test-guard')
end
end
context "without a Guard name" do
context "with an existing Guardfile" do
- before do
- File.stub(:exist?).and_return true
- Dir.stub(:pwd).and_return "/home/user"
- end
+ before { File.should_receive(:exist?).and_return true }
it "shows an error" do
Guard.should_receive(:exit).with 1
::Guard::UI.should_receive(:error).with("Guardfile already exists at /home/user/Guardfile")
- Guard.initialize_template()
+ Guard.initialize_template
end
end
context "without an existing Guardfile" do
- before do
- File.stub(:exist?).and_return false
- Dir.stub(:pwd).and_return "/home/user"
- end
+ before { File.should_receive(:exist?).and_return false }
it "copies the Guardfile template" do
::Guard::UI.should_receive(:info).with("Writing new Guardfile to /home/user/Guardfile")
FileUtils.should_receive(:cp).with(an_instance_of(String), 'Guardfile')
- Guard.initialize_template()
+ Guard.initialize_template
end
end
end

0 comments on commit 1059be0

Please sign in to comment.