Skip to content

Commit

Permalink
Changed that init's parameter has a default value for the current dir…
Browse files Browse the repository at this point in the history
…ectory
  • Loading branch information
soveran committed Aug 4, 2009
1 parent e6ebd0b commit 8b7422e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
15 changes: 11 additions & 4 deletions lib/monk.rb
Expand Up @@ -6,9 +6,10 @@ class Monk < Thor
include Thor::Actions

desc "init", "Initialize a Monk application"
def init(target)
clone(source, target)
cleanup(target)
def init(target = ".")
clone(source, target) ?
cleanup(target) :
say_status(:error, clone_error(target))
end

desc "show NAME", "Display the repository address for NAME"
Expand Down Expand Up @@ -40,11 +41,12 @@ def rm(name)
def clone(source, target)
say_status :fetching, source
system "git clone -q --depth 1 #{source} #{target}"
$?.success?
end

def cleanup(target)
inside(target) { remove_file ".git" }
say_status :create, target
say_status :initialized, target
end

def source(name = "default")
Expand Down Expand Up @@ -73,4 +75,9 @@ def write_monk_config_file
def self.source_root
"."
end

def clone_error(target)
"Couldn't clone repository into target directory '#{target}'. " +
"You must have git installed and the target directory must be empty."
end
end
2 changes: 1 addition & 1 deletion monk.gemspec
Expand Up @@ -15,5 +15,5 @@ Gem::Specification.new do |s|
s.add_dependency("dependencies", ">= 0.0.5")
s.requirements << "git"

s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/monk", "lib/monk.rb", "monk.gemspec", "test/integration_test.rb"]
s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/monk", "lib/monk.rb", "monk.gemspec", "test/commands.rb", "test/integration_test.rb"]
end
4 changes: 2 additions & 2 deletions test/commands.rb
Expand Up @@ -33,12 +33,12 @@ def listening?(host, port)
end
end

def wait_for_service(host, port, timeout = 5)
def wait_for_service(host, port, timeout = 3)
start_time = Time.now

until listening?(host, port)
if timeout && (Time.now > (start_time + timeout))
raise SocketError.new("Socket did not open within #{timeout} seconds")
raise SocketError.new("Socket #{host}:#{port} did not open within #{timeout} seconds")
end
end

Expand Down
32 changes: 30 additions & 2 deletions test/integration_test.rb
Expand Up @@ -19,7 +19,7 @@ def monk(args = nil)
sh("ruby -rubygems #{root "bin/monk"} #{args}")
end

context "monk init" do
context "monk init NAME" do
setup do
@ports_to_close = []
end
Expand Down Expand Up @@ -61,7 +61,7 @@ def try_server(cmd, port)
FileUtils.rm_rf("monk-test")

out, err = monk("init monk-test")
assert_match /create.* monk-test/, out
assert_match /initialized.* monk-test/, out

Dir.chdir("monk-test") do
assert !File.directory?(".git")
Expand Down Expand Up @@ -123,6 +123,34 @@ def kill_suspects(port)
end
end

context "monk init" do
should "fail if the current working directory is not empty" do
Dir.chdir(root("test", "tmp")) do
FileUtils.rm_rf("monk-test")
FileUtils.mkdir("monk-test")


Dir.chdir("monk-test") do
FileUtils.touch("foobar")
out, err = monk("init")
assert_match /error/, out
end
end
end

should "create a skeleton app in the working directory" do
Dir.chdir(root("test", "tmp")) do
FileUtils.rm_rf("monk-test")
FileUtils.mkdir("monk-test")

Dir.chdir("monk-test") do
out, err = monk("init")
assert_match /initialized/, out
end
end
end
end

context "monk show NAME" do
should "display the repository for NAME" do
out, err = monk("show default")
Expand Down

0 comments on commit 8b7422e

Please sign in to comment.