monk 0.0.7 → 1.0.0.beta0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +11 -7
- data/bin/monk +4 -3
- data/lib/monk.rb +68 -14
- data/monk.gemspec +8 -9
- data/test/commands.rb +2 -30
- data/test/helper.rb +36 -0
- data/test/monk_add_NAME_REPOSITORY.rb +32 -0
- data/test/monk_init_NAME.rb +44 -0
- data/test/monk_install.rb +16 -0
- data/test/monk_list.rb +10 -0
- data/test/monk_rm_NAME.rb +11 -0
- data/test/monk_show_NAME.rb +14 -0
- metadata +52 -25
- data/test/integration_test.rb +0 -115
- data/test/monk_test.rb +0 -143
- data/test/test_helper.rb +0 -28
data/Rakefile
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
task :test do
|
2
|
-
|
3
|
-
|
2
|
+
begin
|
3
|
+
require "thor"
|
4
|
+
require "cutest"
|
5
|
+
rescue LoadError
|
6
|
+
puts "! You need `thor` and `cutest` to run the test suite."
|
7
|
+
exit
|
8
|
+
end
|
4
9
|
|
5
|
-
|
10
|
+
Cutest.run(Dir["test/monk_*.rb"])
|
6
11
|
|
7
|
-
|
8
|
-
task :integration do
|
9
|
-
system "cd test && ruby integration_test.rb"
|
10
|
-
end
|
12
|
+
`rvm gemset use monk-test && rvm --force gemset delete monk-test`
|
11
13
|
end
|
14
|
+
|
15
|
+
task :default => :test
|
data/bin/monk
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), "..", "lib", "monk")
|
4
4
|
|
5
|
-
# A way to extend Monk is to write tasks in a Thorfile in the project's root
|
6
|
-
# Monk loads the Thorfile if there is one, and all the tasks that
|
7
|
-
# class Monk become available.
|
5
|
+
# A way to extend Monk is to write tasks in a Thorfile in the project's root
|
6
|
+
# directory. Monk loads the Thorfile if there is one, and all the tasks that
|
7
|
+
# are declared in the class Monk become available.
|
8
8
|
if File.exists?("Thorfile")
|
9
9
|
load("Thorfile")
|
10
10
|
end
|
11
11
|
|
12
12
|
# Start the monk tasks.
|
13
13
|
Monk.start
|
14
|
+
|
data/lib/monk.rb
CHANGED
@@ -10,12 +10,35 @@ class Monk < Thor
|
|
10
10
|
class_options.delete task
|
11
11
|
end
|
12
12
|
|
13
|
-
desc "init", "Initialize a Monk application"
|
13
|
+
desc "init NAME [--skeleton SHORTHAND|URL]", "Initialize a Monk application"
|
14
14
|
method_option :skeleton, :type => :string, :aliases => "-s"
|
15
|
-
def init(target
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def init(target)
|
16
|
+
ensure_rvm
|
17
|
+
clone(target)
|
18
|
+
cleanup(target)
|
19
|
+
create_rvmrc(target)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "install --clean", "Install all dependencies."
|
23
|
+
method_option :clean, :type => :boolean
|
24
|
+
def install(manifest = ".gems")
|
25
|
+
run("rvm rvmrc load")
|
26
|
+
run("rvm --force gemset empty") if options.clean?
|
27
|
+
|
28
|
+
IO.popen("rvm gemset import") do |io|
|
29
|
+
say_status :info, io.readline.gsub(/\(.*?\)/, "") until io.eof?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "lock", "Lock the current dependencies to the gem manifest file."
|
34
|
+
def lock
|
35
|
+
run("rvm rvmrc load")
|
36
|
+
run("rvm gemset export .gems")
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "unpack", "Freeze the current dependencies."
|
40
|
+
def unpack
|
41
|
+
run("rvm gemset unpack")
|
19
42
|
end
|
20
43
|
|
21
44
|
desc "show NAME", "Display the repository address for NAME"
|
@@ -43,13 +66,10 @@ class Monk < Thor
|
|
43
66
|
end
|
44
67
|
|
45
68
|
private
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
system "git clone -q --depth 1 #{source} #{target}"
|
51
|
-
$?.success?
|
52
|
-
end
|
69
|
+
def clone(target)
|
70
|
+
say_status :fetching, repository
|
71
|
+
system "git clone -q --depth 1 #{repository} #{target}"
|
72
|
+
say_status(:error, clone_error(target)) and exit unless $?.success?
|
53
73
|
end
|
54
74
|
|
55
75
|
def cleanup(target)
|
@@ -72,10 +92,10 @@ private
|
|
72
92
|
end
|
73
93
|
end
|
74
94
|
|
75
|
-
def write_monk_config_file
|
95
|
+
def write_monk_config_file(default = "http://github.com/monk/experimental.git")
|
76
96
|
remove_file(monk_config_file, :verbose => false)
|
77
97
|
create_file(monk_config_file, nil, :verbose => false) do
|
78
|
-
config = @monk_config || { "default" =>
|
98
|
+
config = @monk_config || { "default" => default }
|
79
99
|
config.to_yaml
|
80
100
|
end
|
81
101
|
end
|
@@ -92,4 +112,38 @@ private
|
|
92
112
|
def monk_home
|
93
113
|
ENV["MONK_HOME"] || File.join(Thor::Util.user_home)
|
94
114
|
end
|
115
|
+
|
116
|
+
def ensure_rvm
|
117
|
+
begin
|
118
|
+
`rvm`
|
119
|
+
rescue Errno::ENOENT
|
120
|
+
install = "bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )"
|
121
|
+
say_status :error, "Monk requires RVM to be installed."
|
122
|
+
say_status :hint, "To install it, run: #{install}"
|
123
|
+
exit
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def say_indented(str)
|
128
|
+
say str.gsub(/^/, " " * 14)
|
129
|
+
end
|
130
|
+
|
131
|
+
def repository
|
132
|
+
source(options[:skeleton] || "default") or options[:skeleton]
|
133
|
+
end
|
134
|
+
|
135
|
+
def appname(target)
|
136
|
+
target == '.' ? File.basename(Dir.pwd) : target
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_rvmrc(target)
|
140
|
+
target = Dir.pwd if target == "."
|
141
|
+
gemset = File.basename(target)
|
142
|
+
key = [RUBY_VERSION, gemset].join('@')
|
143
|
+
|
144
|
+
inside(target) do
|
145
|
+
run "rvm --rvmrc --create %s && rvm rvmrc trust" % key
|
146
|
+
end
|
147
|
+
end
|
95
148
|
end
|
149
|
+
|
data/monk.gemspec
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "monk"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "1.0.0.beta0"
|
4
4
|
s.summary = "Monk, the glue framework"
|
5
|
-
s.description = "Monk is a glue framework for web development. It
|
5
|
+
s.description = "Monk is a glue framework for web development in Ruby. It’s truly modular by relying on the best tool for each job. It’s also pretty fast thanks to Rack and Sinatra."
|
6
6
|
s.authors = ["Damian Janowski", "Michel Martens"]
|
7
7
|
s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
|
8
8
|
s.homepage = "http://monkrb.com"
|
9
|
-
|
10
|
-
s.rubyforge_project = "monk"
|
11
|
-
|
12
|
-
s.executables << "monk"
|
9
|
+
s.executables.push("monk")
|
13
10
|
|
14
11
|
s.add_dependency("thor", "~> 0.11")
|
15
|
-
s.
|
16
|
-
|
12
|
+
s.add_development_dependency("cutest", "~> 0.1")
|
13
|
+
|
14
|
+
s.requirements.push("git")
|
15
|
+
s.requirements.push("rvm")
|
17
16
|
|
18
|
-
s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/monk", "lib/monk.rb", "monk.gemspec", "test/commands.rb", "test/
|
17
|
+
s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/monk", "lib/monk.rb", "monk.gemspec", "test/commands.rb", "test/helper.rb", "test/monk_add_NAME_REPOSITORY.rb", "test/monk_init_NAME.rb", "test/monk_install.rb", "test/monk_list.rb", "test/monk_rm_NAME.rb", "test/monk_show_NAME.rb"]
|
19
18
|
end
|
data/test/commands.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "open3"
|
2
2
|
require "socket"
|
3
3
|
|
4
|
-
module
|
4
|
+
module Commands
|
5
5
|
def sh(cmd)
|
6
6
|
out, err = nil
|
7
7
|
|
8
8
|
Open3.popen3(cmd) do |_in, _out, _err|
|
9
|
+
yield _in if block_given?
|
9
10
|
out = _out.read
|
10
11
|
err = _err.read
|
11
12
|
end
|
@@ -28,35 +29,6 @@ module Test::Commands
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def listening?(host, port)
|
32
|
-
begin
|
33
|
-
socket = TCPSocket.new(host, port)
|
34
|
-
socket.close unless socket.nil?
|
35
|
-
true
|
36
|
-
rescue Errno::ECONNREFUSED,
|
37
|
-
Errno::EBADF, # Windows
|
38
|
-
Errno::EADDRNOTAVAIL # Windows
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def wait_for_service(host, port, timeout = 3)
|
44
|
-
start_time = Time.now
|
45
|
-
|
46
|
-
until listening?(host, port)
|
47
|
-
if timeout && (Time.now > (start_time + timeout))
|
48
|
-
raise SocketError.new("Socket #{host}:#{port} did not open within #{timeout} seconds")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
true
|
53
|
-
end
|
54
|
-
|
55
|
-
def suspects(port)
|
56
|
-
list = sh("lsof -i :#{port}").first.split("\n")[1..-1] || []
|
57
|
-
list.map {|s| s[/^.+? (\d+)/, 1] }
|
58
|
-
end
|
59
|
-
|
60
32
|
def silence_stream(*streams) #:yeild:
|
61
33
|
on_hold = streams.collect{ |stream| stream.dup }
|
62
34
|
streams.each do |stream|
|
data/test/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "cutest"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
6
|
+
|
7
|
+
$:.unshift ROOT
|
8
|
+
|
9
|
+
require "test/commands"
|
10
|
+
|
11
|
+
include Commands
|
12
|
+
|
13
|
+
TARGET = File.expand_path("tmp/monk-test", File.dirname(__FILE__))
|
14
|
+
|
15
|
+
def root(*args)
|
16
|
+
File.join(ROOT, *args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def monk(args = nil, &block)
|
20
|
+
cmd =
|
21
|
+
"env MONK_HOME=#{root "test/tmp"} " +
|
22
|
+
"ruby -rubygems #{root "bin/monk"} #{args}"
|
23
|
+
|
24
|
+
sh(cmd, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def rvm(args = nil)
|
28
|
+
sh("rvm #{args}")
|
29
|
+
end
|
30
|
+
|
31
|
+
prepare do
|
32
|
+
dot_monk = File.join(ROOT, "test", "tmp", ".monk")
|
33
|
+
|
34
|
+
FileUtils.rm(dot_monk) if File.exist?(dot_monk)
|
35
|
+
`rvm gemset use monk-test && rvm --force gemset delete monk-test`
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
prepare do
|
4
|
+
FileUtils.rm_rf(TARGET)
|
5
|
+
end
|
6
|
+
|
7
|
+
# monk add NAME REPOSITORY
|
8
|
+
scope do
|
9
|
+
test "add the named repository to the configuration" do
|
10
|
+
monk("add foobar http://github.com/monkrb/foo.git")
|
11
|
+
out, _ = monk("show foobar")
|
12
|
+
assert out["foobar"]
|
13
|
+
assert out["http://github.com/monkrb/foo.git"]
|
14
|
+
monk("rm foobar")
|
15
|
+
end
|
16
|
+
|
17
|
+
test "allow to fetch from the added repository with --skeleton parameter" do
|
18
|
+
monk("add glue http://github.com/monkrb/glue.git")
|
19
|
+
|
20
|
+
out, _ = monk("init #{TARGET} --skeleton glue")
|
21
|
+
assert out.match(/initialized/)
|
22
|
+
assert out.match(/glue.git/)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "allow to fetch from the added repository with the -s parameter" do
|
26
|
+
monk("add glue http://github.com/monkrb/glue.git")
|
27
|
+
|
28
|
+
out, _ = monk("init #{TARGET} -s glue")
|
29
|
+
assert out.match(/initialized/)
|
30
|
+
assert out.match(/glue.git/)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
prepare do
|
4
|
+
FileUtils.rm_rf(TARGET)
|
5
|
+
end
|
6
|
+
|
7
|
+
# monk init NAME
|
8
|
+
scope do
|
9
|
+
test "fail if the target working directory is not empty" do
|
10
|
+
FileUtils.mkdir(TARGET)
|
11
|
+
FileUtils.touch(TARGET + "/foo")
|
12
|
+
|
13
|
+
out, err = monk("init #{TARGET}")
|
14
|
+
assert out.match(/error/)
|
15
|
+
end
|
16
|
+
|
17
|
+
test "create a skeleton app in the target directory" do
|
18
|
+
out, err = monk("init #{TARGET}")
|
19
|
+
assert out.match(/initialized.* #{TARGET}/)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "be able to pull from a url instead of a known skeleton" do
|
23
|
+
out, err = monk("init #{TARGET} --skeleton http://github.com/monkrb/skeleton.git")
|
24
|
+
assert out.match(/initialized.* #{TARGET}/)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "create a correct rvmrc given a directory" do
|
28
|
+
monk("init #{TARGET}")
|
29
|
+
|
30
|
+
rvmrc = File.read(File.join(TARGET, ".rvmrc"))
|
31
|
+
assert rvmrc[RUBY_VERSION]
|
32
|
+
assert rvmrc[File.basename(TARGET)]
|
33
|
+
end
|
34
|
+
|
35
|
+
test "create a correct rvmrc given the current directory" do
|
36
|
+
FileUtils.mkdir(TARGET)
|
37
|
+
FileUtils.cd(TARGET) { monk("init .") }
|
38
|
+
|
39
|
+
rvmrc = File.read(File.join(TARGET, ".rvmrc"))
|
40
|
+
assert rvmrc[RUBY_VERSION]
|
41
|
+
assert rvmrc[File.basename(TARGET)]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
prepare do
|
4
|
+
FileUtils.rm_rf(TARGET)
|
5
|
+
end
|
6
|
+
|
7
|
+
test "installs the gems listed in the manifest" do
|
8
|
+
monk("init #{TARGET} --skeleton git://github.com/cyx/empty.git")
|
9
|
+
|
10
|
+
FileUtils.cd(TARGET) do
|
11
|
+
monk("install")
|
12
|
+
|
13
|
+
assert `gem list` =~ /batch/
|
14
|
+
assert `gem list` =~ /cutest/
|
15
|
+
end
|
16
|
+
end
|
data/test/monk_list.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# monk rm NAME
|
4
|
+
scope do
|
5
|
+
test "remove the named repository from the configuration" do
|
6
|
+
monk("add foobar http://github.com/monkrb/foo.git")
|
7
|
+
monk("rm foobar")
|
8
|
+
out, err = monk("show foobar")
|
9
|
+
assert out["repository not found"]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# monk show NAME
|
4
|
+
scope do
|
5
|
+
test "display the repository for NAME" do
|
6
|
+
out, err = monk("show default")
|
7
|
+
assert out["http://github.com/monk/experimental.git"]
|
8
|
+
end
|
9
|
+
|
10
|
+
test "display nothing if NAME is not set" do
|
11
|
+
out, err = monk("show foobar")
|
12
|
+
assert out["repository not found"]
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- beta0
|
10
|
+
version: 1.0.0.beta0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Damian Janowski
|
@@ -10,30 +16,38 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
19
|
+
date: 2010-10-07 00:00:00 -03:00
|
14
20
|
default_executable:
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
17
23
|
name: thor
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
21
27
|
requirements:
|
22
28
|
- - ~>
|
23
29
|
- !ruby/object:Gem::Version
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 11
|
24
33
|
version: "0.11"
|
25
|
-
version:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: dependencies
|
28
34
|
type: :runtime
|
29
|
-
|
30
|
-
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: cutest
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
31
41
|
requirements:
|
32
|
-
- -
|
42
|
+
- - ~>
|
33
43
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 1
|
47
|
+
version: "0.1"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: "Monk is a glue framework for web development in Ruby. It\xE2\x80\x99s truly modular by relying on the best tool for each job. It\xE2\x80\x99s also pretty fast thanks to Rack and Sinatra."
|
37
51
|
email:
|
38
52
|
- djanowski@dimaion.com
|
39
53
|
- michel@soveran.com
|
@@ -51,34 +65,47 @@ files:
|
|
51
65
|
- lib/monk.rb
|
52
66
|
- monk.gemspec
|
53
67
|
- test/commands.rb
|
54
|
-
- test/
|
55
|
-
- test/
|
56
|
-
- test/
|
57
|
-
|
68
|
+
- test/helper.rb
|
69
|
+
- test/monk_add_NAME_REPOSITORY.rb
|
70
|
+
- test/monk_init_NAME.rb
|
71
|
+
- test/monk_install.rb
|
72
|
+
- test/monk_list.rb
|
73
|
+
- test/monk_rm_NAME.rb
|
74
|
+
- test/monk_show_NAME.rb
|
75
|
+
has_rdoc: true
|
58
76
|
homepage: http://monkrb.com
|
77
|
+
licenses: []
|
78
|
+
|
59
79
|
post_install_message:
|
60
80
|
rdoc_options: []
|
61
81
|
|
62
82
|
require_paths:
|
63
83
|
- lib
|
64
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
65
86
|
requirements:
|
66
87
|
- - ">="
|
67
88
|
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
68
91
|
version: "0"
|
69
|
-
version:
|
70
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
71
94
|
requirements:
|
72
|
-
- - "
|
95
|
+
- - ">"
|
73
96
|
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 3
|
100
|
+
- 1
|
101
|
+
version: 1.3.1
|
76
102
|
requirements:
|
77
103
|
- git
|
78
|
-
|
79
|
-
|
104
|
+
- rvm
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.3.7
|
80
107
|
signing_key:
|
81
|
-
specification_version:
|
108
|
+
specification_version: 3
|
82
109
|
summary: Monk, the glue framework
|
83
110
|
test_files: []
|
84
111
|
|
data/test/integration_test.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
-
|
3
|
-
class TestMonk < Test::Unit::TestCase
|
4
|
-
context "monk init NAME" do
|
5
|
-
setup do
|
6
|
-
@ports_to_close = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def assert_url(url)
|
10
|
-
assert_match /200 OK/, sh("curl -I 0.0.0.0:4567#{url}").first.split("\n").first
|
11
|
-
end
|
12
|
-
|
13
|
-
def try_server(cmd, port)
|
14
|
-
binary = cmd[/^(.+?)( |$)/, 1]
|
15
|
-
|
16
|
-
flunk "Can't find `#{binary}`." unless system("which #{binary} > /dev/null")
|
17
|
-
|
18
|
-
kill_suspects(port)
|
19
|
-
sh_bg(cmd)
|
20
|
-
|
21
|
-
# Mark the port for closing on teardown, just in case the build fails.
|
22
|
-
@ports_to_close << port if wait_for_service("0.0.0.0", port)
|
23
|
-
|
24
|
-
doc = Hpricot(sh("curl 0.0.0.0:#{port}").first)
|
25
|
-
|
26
|
-
assert_match /Hello, world/, doc.at("body").inner_text
|
27
|
-
|
28
|
-
# Make sure all referenced URLs in the layout respond correctly.
|
29
|
-
doc.search("//*[@href]").each do |node|
|
30
|
-
assert_url node.attributes["href"]
|
31
|
-
end
|
32
|
-
|
33
|
-
doc.search("//*[@src]").each do |node|
|
34
|
-
assert_url node.attributes["src"]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
should "create a skeleton app with all tests passing" do
|
39
|
-
flunk "There is another server running on 0.0.0.0:4567. Suspect PIDs: #{suspects(4567).join(", ")}" if listening?("0.0.0.0", 4567)
|
40
|
-
flunk "There is another server running on 0.0.0.0:9292. Suspect PIDs: #{suspects(9292).join(", ")}" if listening?("0.0.0.0", 9292)
|
41
|
-
|
42
|
-
Dir.chdir(root("test", "tmp")) do
|
43
|
-
FileUtils.rm_rf("monk-test")
|
44
|
-
|
45
|
-
out, err = monk("init monk-test")
|
46
|
-
assert_match /initialized.* monk-test/, out
|
47
|
-
|
48
|
-
Dir.chdir("monk-test") do
|
49
|
-
assert !File.directory?(".git")
|
50
|
-
|
51
|
-
FileUtils.cp("config/settings.example.yml", "config/settings.yml")
|
52
|
-
FileUtils.cp("config/redis/development.example.conf", "config/redis/development.conf")
|
53
|
-
FileUtils.cp("config/redis/test.example.conf", "config/redis/test.conf")
|
54
|
-
|
55
|
-
# Load Redis.
|
56
|
-
sh "redis-server config/redis/test.conf"
|
57
|
-
wait_for_service("0.0.0.0", 6380)
|
58
|
-
|
59
|
-
sh "redis-server config/redis/development.conf"
|
60
|
-
wait_for_service("0.0.0.0", 6379)
|
61
|
-
|
62
|
-
assert system("rake >/dev/null"), "the build didn't pass"
|
63
|
-
assert system("rake1.9 >/dev/null"), "the build didn't pass (1.9)"
|
64
|
-
|
65
|
-
try_server "ruby init.rb", 4567
|
66
|
-
try_reloading
|
67
|
-
try_server "rackup", 9292
|
68
|
-
|
69
|
-
try_server "ruby1.9 init.rb", 4567
|
70
|
-
try_reloading
|
71
|
-
try_server "rackup1.9", 9292
|
72
|
-
|
73
|
-
try_server "jruby init.rb", 4567
|
74
|
-
try_reloading
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def try_reloading
|
80
|
-
gsub_file("app/routes/home.rb", "haml :home", "'Goodbye'") do
|
81
|
-
sleep 0.2
|
82
|
-
assert_match /Goodbye/, sh("curl 0.0.0.0:4567").first
|
83
|
-
end
|
84
|
-
|
85
|
-
gsub_file("init.rb", "Main.run!", %Q(Main.get "/test" { 'test' }\n Main.run!)) do
|
86
|
-
sleep 0.2
|
87
|
-
assert_match /test/, sh("curl 0.0.0.0:4567/test").first
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def gsub_file(file, *args)
|
92
|
-
old = File.read(file)
|
93
|
-
|
94
|
-
begin
|
95
|
-
new = old.gsub(*args)
|
96
|
-
File.open(file, "w") {|f| f.write(new) }
|
97
|
-
yield
|
98
|
-
ensure
|
99
|
-
File.open(file, "w") {|f| f.write(old) }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def kill_suspects(port)
|
104
|
-
list = suspects(port)
|
105
|
-
|
106
|
-
sh "kill -9 #{list.join(" ")}" unless list.empty?
|
107
|
-
end
|
108
|
-
|
109
|
-
teardown do
|
110
|
-
@ports_to_close.each do |port|
|
111
|
-
kill_suspects port
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/test/monk_test.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
-
|
3
|
-
class TestMonk < Test::Unit::TestCase
|
4
|
-
context "monk init NAME" do
|
5
|
-
should "fail if the target working directory is not empty" do
|
6
|
-
Dir.chdir(root("test", "tmp")) do
|
7
|
-
FileUtils.rm_rf("monk-test")
|
8
|
-
FileUtils.mkdir("monk-test")
|
9
|
-
|
10
|
-
Dir.chdir("monk-test") do
|
11
|
-
FileUtils.touch("foobar")
|
12
|
-
end
|
13
|
-
|
14
|
-
out, err = monk("init monk-test")
|
15
|
-
assert_match /error/, out
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
should "create a skeleton app in the target directory" do
|
20
|
-
Dir.chdir(root("test", "tmp")) do
|
21
|
-
FileUtils.rm_rf("monk-test")
|
22
|
-
|
23
|
-
out, err = monk("init monk-test")
|
24
|
-
assert_match /initialized.* monk-test/, out
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
should "be able to pull from a url instead of a known skeleton" do
|
29
|
-
Dir.chdir(root("test", "tmp")) do
|
30
|
-
FileUtils.rm_rf "monk-test"
|
31
|
-
out, err = monk("init monk-test --skeleton git://github.com/monkrb/skeleton.git")
|
32
|
-
assert_match /initialized.* monk-test/, out
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "monk init" do
|
38
|
-
should "fail if the current working directory is not empty" do
|
39
|
-
Dir.chdir(root("test", "tmp")) do
|
40
|
-
FileUtils.rm_rf("monk-test")
|
41
|
-
FileUtils.mkdir("monk-test")
|
42
|
-
|
43
|
-
|
44
|
-
Dir.chdir("monk-test") do
|
45
|
-
FileUtils.touch("foobar")
|
46
|
-
out, err = monk("init")
|
47
|
-
assert_match /error/, out
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
should "create a skeleton app in the working directory" do
|
53
|
-
Dir.chdir(root("test", "tmp")) do
|
54
|
-
FileUtils.rm_rf("monk-test")
|
55
|
-
FileUtils.mkdir("monk-test")
|
56
|
-
|
57
|
-
Dir.chdir("monk-test") do
|
58
|
-
out, err = monk("init")
|
59
|
-
assert_match /initialized/, out
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
should "use an alternative skeleton if the option is provided" do
|
65
|
-
Dir.chdir(root("test", "tmp")) do
|
66
|
-
FileUtils.rm_rf("monk-test")
|
67
|
-
FileUtils.mkdir("monk-test")
|
68
|
-
|
69
|
-
monk("add foobar git://github.com/monkrb/skeleton.git")
|
70
|
-
|
71
|
-
Dir.chdir("monk-test") do
|
72
|
-
out, err = monk("init -s foobar")
|
73
|
-
assert_match /initialized/, out
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "monk show NAME" do
|
80
|
-
should "display the repository for NAME" do
|
81
|
-
out, err = monk("show default")
|
82
|
-
assert out["git://github.com/monkrb/skeleton.git"]
|
83
|
-
end
|
84
|
-
|
85
|
-
should "display nothing if NAME is not set" do
|
86
|
-
out, err = monk("show foobar")
|
87
|
-
assert out["repository not found"]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "monk list" do
|
92
|
-
should "display the configured repositories" do
|
93
|
-
out, err = monk("list")
|
94
|
-
assert out["default"]
|
95
|
-
assert out["git://github.com/monkrb/skeleton.git"]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "monk add NAME REPOSITORY" do
|
100
|
-
should "add the named repository to the configuration" do
|
101
|
-
monk("add foobar git://github.com/monkrb/foo.git")
|
102
|
-
out, err = monk("show foobar")
|
103
|
-
assert out["foobar"]
|
104
|
-
assert out["git://github.com/monkrb/foo.git"]
|
105
|
-
monk("rm foobar")
|
106
|
-
end
|
107
|
-
|
108
|
-
should "allow to fetch from the added repository when using the skeleton parameter" do
|
109
|
-
monk("add glue git://github.com/monkrb/glue.git")
|
110
|
-
|
111
|
-
Dir.chdir(root("test", "tmp")) do
|
112
|
-
FileUtils.rm_rf("monk-test")
|
113
|
-
FileUtils.mkdir("monk-test")
|
114
|
-
|
115
|
-
out, err = monk("init monk-test --skeleton glue")
|
116
|
-
assert_match /initialized/, out
|
117
|
-
assert_match /glue.git/, out
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
should "allow to fetch from the added repository when using the s parameter" do
|
122
|
-
monk("add glue git://github.com/monkrb/glue.git")
|
123
|
-
|
124
|
-
Dir.chdir(root("test", "tmp")) do
|
125
|
-
FileUtils.rm_rf("monk-test")
|
126
|
-
FileUtils.mkdir("monk-test")
|
127
|
-
|
128
|
-
out, err = monk("init monk-test -s glue")
|
129
|
-
assert_match /initialized/, out
|
130
|
-
assert_match /glue.git/, out
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "monk rm NAME" do
|
136
|
-
should "remove the named repository from the configuration" do
|
137
|
-
monk("add foobar git://github.com/monkrb/foo.git")
|
138
|
-
monk("rm foobar")
|
139
|
-
out, err = monk("show foobar")
|
140
|
-
assert out["repository not found"]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "contest"
|
3
|
-
require "hpricot"
|
4
|
-
require "fileutils"
|
5
|
-
|
6
|
-
ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
7
|
-
|
8
|
-
$:.unshift ROOT
|
9
|
-
|
10
|
-
require "test/commands"
|
11
|
-
|
12
|
-
class Test::Unit::TestCase
|
13
|
-
include Test::Commands
|
14
|
-
|
15
|
-
def root(*args)
|
16
|
-
File.join(ROOT, *args)
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
dot_monk = File.join(ROOT, "test", "tmp", ".monk")
|
21
|
-
|
22
|
-
FileUtils.rm(dot_monk) if File.exist?(dot_monk)
|
23
|
-
end
|
24
|
-
|
25
|
-
def monk(args = nil)
|
26
|
-
sh("env MONK_HOME=#{File.join(ROOT, "test", "tmp")} ruby -rubygems #{root "bin/monk"} #{args}")
|
27
|
-
end
|
28
|
-
end
|