rkh-monk 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/monk/skeleton.rb +111 -0
- data/lib/monk.rb +114 -84
- data/monk.gemspec +3 -3
- data/test/integration_test.rb +3 -0
- data/test/monk_test.rb +282 -35
- data/test/test_helper.rb +63 -0
- metadata +5 -4
data/Rakefile
CHANGED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'thor/core_ext/hash_with_indifferent_access'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'monk'
|
4
|
+
|
5
|
+
class Monk < Thor
|
6
|
+
class Skeleton
|
7
|
+
|
8
|
+
include Thor::CoreExt
|
9
|
+
include FileUtils
|
10
|
+
attr_accessor :options, :target
|
11
|
+
|
12
|
+
DEFAULTS = { "remote_name" => "skeleton", "branch" => "master" }
|
13
|
+
|
14
|
+
def initialize(url = nil, opts = {})
|
15
|
+
opts, url = opts.merge(url), nil if url.respond_to? :merge
|
16
|
+
self.options = HashWithIndifferentAccess.new opts
|
17
|
+
options[:url] ||= url
|
18
|
+
raise ArgumentError, "no url given" unless options.url?
|
19
|
+
end
|
20
|
+
|
21
|
+
def mirror_path
|
22
|
+
return unless mirror?
|
23
|
+
options[:mirror_path] ||= begin
|
24
|
+
require 'digest/md5'
|
25
|
+
File.join(Monk.monk_mirrors, Digest::MD5.hexdigest(options[:url]))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_mirror
|
30
|
+
return unless mirror?
|
31
|
+
if File.exist? mirror_path
|
32
|
+
chdir(mirror_path) { system "git pull origin -q >/dev/null 2>&1"}
|
33
|
+
else
|
34
|
+
mkdir_p Monk.monk_mirrors
|
35
|
+
system "git clone -q #{url} #{mirror_path}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create(directory)
|
40
|
+
update_mirror
|
41
|
+
if Dir["#{directory}/*"].empty?
|
42
|
+
self.target = directory
|
43
|
+
return false unless clone_command
|
44
|
+
clean_up unless keep_remote?
|
45
|
+
true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def advanced_clone?
|
50
|
+
branch? or keep_remote?
|
51
|
+
end
|
52
|
+
|
53
|
+
def clone_command
|
54
|
+
advanced_clone? ? advanced_clone : fast_clone
|
55
|
+
end
|
56
|
+
|
57
|
+
def mirror_url
|
58
|
+
mirror? ? mirror_path : url
|
59
|
+
end
|
60
|
+
|
61
|
+
def fast_clone
|
62
|
+
system "git clone -q --depth 1 #{mirror_url} #{target}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def advanced_clone
|
66
|
+
mkdir_p target
|
67
|
+
Dir.chdir target do
|
68
|
+
system "(git init -q &&
|
69
|
+
git remote add -t #{branch} -f #{remote_name} #{mirror_url} &&
|
70
|
+
git checkout -t #{remote_name}/#{branch} -q) >/dev/null 2>&1"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def clean_up
|
75
|
+
Dir.chdir(target) { system "rm -Rf .git" }
|
76
|
+
end
|
77
|
+
|
78
|
+
def config
|
79
|
+
options.keys == ["url"] ? options["url"] : Hash.new.replace(options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_yaml(opts = {})
|
83
|
+
config.to_yaml(opts)
|
84
|
+
end
|
85
|
+
|
86
|
+
def description
|
87
|
+
parameters = options.map do |key, value|
|
88
|
+
case key
|
89
|
+
when "url", "mirror_path" then nil
|
90
|
+
when "mirror", "keep_remote"
|
91
|
+
"#{"no-" unless value}#{key.gsub("_", "-")}"
|
92
|
+
else
|
93
|
+
"#{key}: #{value.inspect}"
|
94
|
+
end
|
95
|
+
end.compact.join ", "
|
96
|
+
parameters = "(#{parameters})" unless parameters.empty?
|
97
|
+
"#{url} #{parameters}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def method_missing(name, *args, &block)
|
101
|
+
name = name.to_s
|
102
|
+
return options[name] || DEFAULTS[name] if Monk.git_options.include? name
|
103
|
+
result = options.send(name, *args, &block)
|
104
|
+
if result.equal? options then self
|
105
|
+
elsif result.is_a? Hash then Skeleton.new result
|
106
|
+
else result
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
data/lib/monk.rb
CHANGED
@@ -1,109 +1,140 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
4
|
+
|
3
5
|
require "thor"
|
4
6
|
require "yaml"
|
5
|
-
|
7
|
+
|
8
|
+
require "monk/skeleton"
|
6
9
|
|
7
10
|
class Monk < Thor
|
8
11
|
include Thor::Actions
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
method_option :keep_remote, :type => :boolean
|
17
|
-
method_option :remote_name, :type => :string
|
18
|
-
end
|
13
|
+
class_options[:skip].aliases.delete "-s"
|
14
|
+
|
15
|
+
def self.git_option(name, options = {})
|
16
|
+
class_option name, options.merge(:group => :git)
|
17
|
+
git_options << name.to_s
|
18
|
+
end
|
19
19
|
|
20
|
+
def self.git_options
|
21
|
+
@git_options ||= ["mirror_path"]
|
20
22
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
|
24
|
+
def self.monk_home
|
25
|
+
ENV["MONK_HOME"] || File.join(Thor::Util.user_home)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.monk_mirrors
|
29
|
+
File.join(monk_home, ".monk_mirrors")
|
30
|
+
end
|
31
|
+
|
32
|
+
git_option :branch, :type => :string, :aliases => "-b",
|
33
|
+
:desc => "Specify skeleton branch to use."
|
34
|
+
git_option :keep_remote, :type => :boolean, :aliases => "-k",
|
35
|
+
:desc => "Do not remove .git folder and keep skeleton as remote"
|
36
|
+
git_option :remote_name, :type => :string, :aliases => "-r",
|
37
|
+
:desc => "Remote name to use for the skeleton. Default is skeleton"
|
38
|
+
git_option :mirror, :type => :boolean, :aliases => "-m",
|
39
|
+
:desc => "Keep local mirror of the skeleton. For offline use and frequent project creation"
|
40
|
+
|
41
|
+
desc "init", "Initialize a Monk application. Will try to update mirror for given skeleton."
|
42
|
+
method_option :skeleton, :type => :string, :aliases => "-s"
|
25
43
|
def init(target = ".")
|
26
|
-
|
27
|
-
|
44
|
+
say_status :fetching, skeleton.url
|
45
|
+
skeleton.create(target) ?
|
46
|
+
say_status(:initialized, target) :
|
28
47
|
say_status(:error, clone_error(target))
|
29
48
|
end
|
30
|
-
|
49
|
+
|
31
50
|
desc "show NAME", "Display the repository address for NAME"
|
32
51
|
def show(name)
|
33
|
-
|
34
|
-
say_status name, *source(name).values_at(:url, :branch)
|
35
|
-
else
|
36
|
-
say_status name, "repository not found"
|
37
|
-
end
|
52
|
+
say_status name, monk_config[name] ? skeleton(name).description : "repository not found"
|
38
53
|
end
|
39
54
|
|
40
55
|
desc "list", "Lists the configured repositories"
|
41
56
|
def list
|
42
|
-
monk_config.keys.sort.each
|
43
|
-
show(key)
|
44
|
-
end
|
57
|
+
monk_config.keys.sort.each { |key| show(key) }
|
45
58
|
end
|
46
59
|
|
47
60
|
desc "add NAME REPOSITORY_URL", "Add the repository to the configuration file"
|
48
|
-
git_options
|
49
61
|
def add(name, repository_url)
|
50
|
-
monk_config[name] =
|
51
|
-
monk_config[name].merge!
|
62
|
+
monk_config[name] = Skeleton.new(repository_url)
|
63
|
+
monk_config[name].merge! git_options
|
64
|
+
monk_config[name].update_mirror
|
52
65
|
write_monk_config_file
|
53
|
-
|
66
|
+
say_status :added, name
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "change NAME", "Modifies options for a repository without having to repeat the url"
|
70
|
+
def change(name)
|
71
|
+
if monk_config.include? name
|
72
|
+
monk_config[name].merge! git_options
|
73
|
+
if options.include? "mirror" and not options.mirror?
|
74
|
+
path = monk_config[name].delete "mirror_path"
|
75
|
+
system "rm -R #{path}" if path
|
76
|
+
end
|
77
|
+
write_monk_config_file
|
78
|
+
say_status :modified, name
|
79
|
+
else
|
80
|
+
say_status name, "repository not found"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "rm NAME", "Remove the repository from the configuration file"
|
85
|
+
def rm(name)
|
86
|
+
skel = monk_config.delete(name)
|
87
|
+
write_monk_config_file
|
88
|
+
system "rm -R #{skel.mirror_path}" if skel.mirror_path?
|
89
|
+
say_status :deleted, name
|
90
|
+
end
|
91
|
+
|
92
|
+
desc "copy FROM TO", "Creates a copy of an existing skeleton"
|
93
|
+
def copy(from, to)
|
94
|
+
return unless monk_config.include? from
|
95
|
+
monk_config[to] = skeleton(from)
|
96
|
+
monk_config[to].delete "mirror_path"
|
97
|
+
write_monk_config_file
|
98
|
+
say_status :added, to
|
99
|
+
end
|
100
|
+
|
101
|
+
desc "cleanup", "Removes mirrors no longer used (or all mirrors with --all)"
|
102
|
+
method_option :all, :type => :boolean, :aliases => "-a"
|
103
|
+
def cleanup
|
104
|
+
say_status "scanning", "mirrors"
|
105
|
+
mirrors = Dir.glob File.join(Monk.monk_mirrors, "*")
|
106
|
+
monk_config.each_value do |skel|
|
107
|
+
mirrors.delete skel.mirror_path if skel.mirror_path?
|
108
|
+
end unless options["all"]
|
109
|
+
say_status "cleanup", "mirrors"
|
110
|
+
system "rm -R #{mirrors.join " "}"
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "update", "Updates all mirrors or mirrors for given skeleton."
|
114
|
+
def update(name = nil)
|
115
|
+
name ||= options[:skeleton]
|
116
|
+
return monk_config.each_key { |s| update(s) } unless name
|
117
|
+
skel = skeleton(name)
|
118
|
+
if skel.mirror?
|
119
|
+
say_status "update", name
|
120
|
+
skel.update_mirror
|
121
|
+
end
|
122
|
+
end
|
54
123
|
|
55
|
-
desc "change NAME", "Modifies options for a repository without having to repeat the url."
|
56
|
-
git_options
|
57
|
-
def change(name)
|
58
|
-
if monk_config.include? name
|
59
|
-
monk_config[name].merge! options
|
60
|
-
write_monk_config_file
|
61
|
-
else
|
62
|
-
say_status name, "repository not found"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
desc "rm NAME", "Remove the repository from the configuration file"
|
67
|
-
def rm(name)
|
68
|
-
monk_config.delete(name)
|
69
|
-
write_monk_config_file
|
70
|
-
end
|
71
|
-
|
72
|
-
desc "copy FROM TO", "Creates a copy of an existing skeleton."
|
73
|
-
git_options
|
74
|
-
def copy(from, to)
|
75
|
-
return unless monk_config.include? from
|
76
|
-
monk_config[to] = monk_config[from].merge options
|
77
|
-
write_monk_config_file
|
78
|
-
end
|
79
124
|
|
80
125
|
private
|
81
126
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
Dir.chdir(target) do
|
86
|
-
say_status :fetching, src[:url]
|
87
|
-
branch = src[:branch] || "master"
|
88
|
-
remote = src[:remote_name] || "skeleton"
|
89
|
-
system <<-EOS
|
90
|
-
git init &&
|
91
|
-
git remote add -t #{branch} -f #{remote} #{src[:url]} &&
|
92
|
-
git checkout -t #{remote}/#{branch}
|
93
|
-
EOS
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def cleanup(target)
|
99
|
-
inside(target) { remove_file ".git" } unless options.keep_remote?
|
100
|
-
say_status :initialized, target
|
101
|
-
end
|
102
|
-
|
103
|
-
def source(name)
|
104
|
-
monk_config[name]
|
127
|
+
def skeleton(name = nil)
|
128
|
+
name ||= options[:skeleton] || "default"
|
129
|
+
(monk_config[name] || Skeleton.new(name)).merge git_options
|
105
130
|
end
|
106
131
|
|
132
|
+
def git_options
|
133
|
+
self.class.git_options.inject({}) do |opts, key|
|
134
|
+
opts.merge! key => options[key] if options.include? key
|
135
|
+
opts
|
136
|
+
end
|
137
|
+
end
|
107
138
|
|
108
139
|
def monk_config_file
|
109
140
|
@monk_config_file ||= File.join(monk_home, ".monk")
|
@@ -113,20 +144,19 @@ private
|
|
113
144
|
@monk_config ||= begin
|
114
145
|
write_monk_config_file unless File.exists? monk_config_file
|
115
146
|
YAML.load_file(monk_config_file).inject({}) do |config, (key, value)|
|
116
|
-
|
117
|
-
config.merge key => value.respond_to?(:keys) ? value : {:url => value}
|
147
|
+
config.merge key => Skeleton.new(value)
|
118
148
|
end
|
119
149
|
end
|
120
150
|
end
|
121
151
|
|
122
152
|
def write_monk_config_file
|
123
|
-
remove_file monk_config_file
|
124
|
-
create_file
|
125
|
-
config = @monk_config || { "default" =>
|
153
|
+
remove_file monk_config_file, :verbose => false
|
154
|
+
create_file(monk_config_file, nil, :verbose => false) do
|
155
|
+
config = @monk_config || { "default" => Skeleton.new("git://github.com/monkrb/skeleton.git") }
|
126
156
|
config.to_yaml
|
127
157
|
end
|
128
158
|
end
|
129
|
-
|
159
|
+
|
130
160
|
def self.source_root
|
131
161
|
"."
|
132
162
|
end
|
@@ -137,6 +167,6 @@ private
|
|
137
167
|
end
|
138
168
|
|
139
169
|
def monk_home
|
140
|
-
|
170
|
+
self.class.monk_home
|
141
171
|
end
|
142
|
-
end
|
172
|
+
end
|
data/monk.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "monk"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.6"
|
4
4
|
s.summary = "Monk, the glue framework"
|
5
5
|
s.description = "Monk is a glue framework for web development. It means that instead of installing all the tools you need for your projects, you can rely on a git repository and a list of dependencies, and Monk will care of the rest. By default, it ships with a Sinatra application that includes Contest, Stories, Webrat, Ohm and some other niceties, along with a structure and helpful documentation to get your hands wet in no time."
|
6
6
|
s.authors = ["Damian Janowski", "Michel Martens"]
|
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.executables << "monk"
|
13
13
|
|
14
14
|
s.add_dependency("thor", "~> 0.11")
|
15
|
-
s.add_dependency("dependencies", ">= 0.0.
|
15
|
+
s.add_dependency("dependencies", ">= 0.0.7")
|
16
16
|
s.requirements << "git"
|
17
17
|
|
18
|
-
s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/monk", "lib/monk.rb", "monk.gemspec", "test/commands.rb", "test/integration_test.rb", "test/monk_test.rb"]
|
18
|
+
s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/monk", "lib/monk/skeleton.rb", "lib/monk.rb", "monk.gemspec", "test/commands.rb", "test/integration_test.rb", "test/monk_test.rb", "test/test_helper.rb"]
|
19
19
|
end
|
data/test/integration_test.rb
CHANGED
data/test/monk_test.rb
CHANGED
@@ -3,12 +3,12 @@ require File.join(File.dirname(__FILE__), "test_helper")
|
|
3
3
|
class TestMonk < Test::Unit::TestCase
|
4
4
|
context "monk init NAME" do
|
5
5
|
should "fail if the target working directory is not empty" do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
chdir tmp_path do
|
7
|
+
rm_rf("monk-test")
|
8
|
+
mkdir("monk-test")
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
chdir("monk-test") do
|
11
|
+
touch("foobar")
|
12
12
|
end
|
13
13
|
|
14
14
|
out, err = monk("init monk-test")
|
@@ -17,24 +17,125 @@ class TestMonk < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
should "create a skeleton app in the target directory" do
|
20
|
-
|
21
|
-
|
20
|
+
chdir tmp_path do
|
21
|
+
rm_rf("monk-test")
|
22
22
|
|
23
23
|
out, err = monk("init monk-test")
|
24
24
|
assert_match /initialized.* monk-test/, out
|
25
|
+
assert is_template?("monk-test", "default")
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
should "not remove .git if keep-remote option is passed" do
|
30
|
+
chdir tmp_path do
|
31
|
+
rm_rf("monk-test")
|
32
|
+
|
33
|
+
out, err = monk("init monk-test --keep-remote")
|
34
|
+
assert_match /initialized.* monk-test/, out
|
35
|
+
assert File.exist?(tmp_path("monk-test", ".git"))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
should "remove .git if no-keep-remote option is passed" do
|
40
|
+
chdir tmp_path do
|
41
|
+
rm_rf("monk-test")
|
42
|
+
|
43
|
+
out, err = monk("init monk-test --no-keep-remote")
|
44
|
+
assert_match /initialized.* monk-test/, out
|
45
|
+
assert !File.exist?(tmp_path("monk-test", ".git"))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
should "not remove .git if k option is passed" do
|
50
|
+
chdir tmp_path do
|
51
|
+
rm_rf("monk-test")
|
52
|
+
|
53
|
+
out, err = monk("init monk-test -k")
|
54
|
+
assert_match /initialized.* monk-test/, out
|
55
|
+
assert File.exist?(tmp_path("monk-test", ".git"))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
should "name remote after remote-name parameter" do
|
60
|
+
chdir tmp_path do
|
61
|
+
rm_rf "monk-test"
|
62
|
+
out, err = monk("init monk-test --keep-remote --remote-name foo")
|
63
|
+
assert_match /initialized.* monk-test/, out
|
64
|
+
chdir("monk-test") { assert %x[git remote show]["foo"] }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
should "be able to pull from skeletons with parameter mirror if original is not available" do
|
69
|
+
chdir tmp_path do
|
70
|
+
rm_rf "monk-test"
|
71
|
+
rm_rf create_template("foo", "--mirror")
|
72
|
+
out, err = monk("init monk-test --skeleton foo")
|
73
|
+
assert_match /initialized.* monk-test/, out
|
74
|
+
assert is_template?("monk-test", "foo")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
should "be able to pull from skeletons with parameter m if original is not available" do
|
79
|
+
chdir tmp_path do
|
80
|
+
rm_rf "monk-test"
|
81
|
+
rm_rf create_template("foo", "-m")
|
82
|
+
out, err = monk("init monk-test --skeleton foo")
|
83
|
+
assert_match /initialized.* monk-test/, out
|
84
|
+
assert is_template?("monk-test", "foo")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
should "be able to pull from a url instead of a known skeleton" do
|
89
|
+
chdir tmp_path do
|
90
|
+
rm_rf "monk-test"
|
91
|
+
path = create_template("foo")
|
92
|
+
out, err = monk("init monk-test --skeleton #{path}")
|
93
|
+
assert_match /initialized.* monk-test/, out
|
94
|
+
assert is_template?("monk-test", "foo")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
should "respect the branch parameter" do
|
99
|
+
chdir tmp_path do
|
100
|
+
in_template "foobar" do
|
101
|
+
system "git checkout -b foo 1>/dev/null 2>&1 || git checkout foo -q"
|
102
|
+
File.open("only_in_branch", "w").close
|
103
|
+
system "(git add only_in_branch && git commit -a -m 'added') 1>/dev/null 2>&1"
|
104
|
+
end
|
105
|
+
rm_rf "monk-test"
|
106
|
+
out, err = monk("init monk-test --skeleton foobar --branch foo")
|
107
|
+
assert_match /initialized.* monk-test/, out
|
108
|
+
assert is_template?("monk-test", "foobar")
|
109
|
+
assert File.exist?(File.join("monk-test", "only_in_branch"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
should "respect the b parameter" do
|
114
|
+
chdir tmp_path do
|
115
|
+
in_template "foobar" do
|
116
|
+
system "git checkout -b foo 1>/dev/null 2>&1 || git checkout foo -q"
|
117
|
+
File.open("only_in_branch", "w").close
|
118
|
+
system "(git add only_in_branch && git commit -a -m 'added') 1>/dev/null 2>&1"
|
119
|
+
end
|
120
|
+
rm_rf "monk-test"
|
121
|
+
out, err = monk("init monk-test --skeleton foobar -b foo")
|
122
|
+
assert_match /initialized.* monk-test/, out
|
123
|
+
assert is_template?("monk-test", "foobar")
|
124
|
+
assert File.exist?(File.join("monk-test", "only_in_branch"))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
27
128
|
end
|
28
129
|
|
29
130
|
context "monk init" do
|
30
131
|
should "fail if the current working directory is not empty" do
|
31
|
-
|
32
|
-
|
33
|
-
|
132
|
+
chdir tmp_path do
|
133
|
+
rm_rf("monk-test")
|
134
|
+
mkdir("monk-test")
|
34
135
|
|
35
136
|
|
36
|
-
|
37
|
-
|
137
|
+
chdir("monk-test") do
|
138
|
+
touch("foobar")
|
38
139
|
out, err = monk("init")
|
39
140
|
assert_match /error/, out
|
40
141
|
end
|
@@ -42,36 +143,103 @@ class TestMonk < Test::Unit::TestCase
|
|
42
143
|
end
|
43
144
|
|
44
145
|
should "create a skeleton app in the working directory" do
|
45
|
-
|
46
|
-
|
47
|
-
|
146
|
+
chdir tmp_path do
|
147
|
+
rm_rf("monk-test")
|
148
|
+
mkdir("monk-test")
|
48
149
|
|
49
|
-
|
150
|
+
chdir("monk-test") do
|
50
151
|
out, err = monk("init")
|
51
152
|
assert_match /initialized/, out
|
153
|
+
assert is_template?(".", "default")
|
52
154
|
end
|
53
155
|
end
|
54
156
|
end
|
55
157
|
|
56
158
|
should "use an alternative skeleton if the option is provided" do
|
57
|
-
|
58
|
-
|
59
|
-
|
159
|
+
chdir tmp_path do
|
160
|
+
rm_rf("monk-test")
|
161
|
+
mkdir("monk-test")
|
60
162
|
|
61
|
-
|
163
|
+
create_template "foobar"
|
62
164
|
|
63
|
-
|
165
|
+
chdir("monk-test") do
|
64
166
|
out, err = monk("init -s foobar")
|
65
167
|
assert_match /initialized/, out
|
168
|
+
assert is_template?(".", "foobar")
|
66
169
|
end
|
67
170
|
end
|
68
171
|
end
|
172
|
+
|
173
|
+
should "not remove .git if keep-remote option is passed" do
|
174
|
+
chdir tmp_path do
|
175
|
+
rm_rf("monk-test")
|
176
|
+
mkdir("monk-test")
|
177
|
+
|
178
|
+
chdir("monk-test") do
|
179
|
+
out, err = monk("init --keep-remote")
|
180
|
+
assert_match /initialized/, out
|
181
|
+
assert File.exist?(".git")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
should "remove .git if no-keep-remote option is passed" do
|
187
|
+
chdir tmp_path do
|
188
|
+
rm_rf("monk-test")
|
189
|
+
mkdir("monk-test")
|
190
|
+
|
191
|
+
chdir("monk-test") do
|
192
|
+
out, err = monk("init --no-keep-remote")
|
193
|
+
assert_match /initialized/, out
|
194
|
+
assert !File.exist?(".git")
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
should "not remove .git if k option is passed" do
|
200
|
+
chdir tmp_path do
|
201
|
+
rm_rf("monk-test")
|
202
|
+
mkdir("monk-test")
|
203
|
+
|
204
|
+
chdir("monk-test") do
|
205
|
+
out, err = monk("init -k")
|
206
|
+
assert_match /initialized/, out
|
207
|
+
assert File.exist?(".git")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
should "name remote after remote-name parameter" do
|
213
|
+
chdir tmp_path do
|
214
|
+
rm_rf "monk-test"
|
215
|
+
mkdir "monk-test"
|
216
|
+
chdir "monk-test" do
|
217
|
+
out, err = monk("init --keep-remote --remote-name foo")
|
218
|
+
assert_match /initialized/, out
|
219
|
+
assert %x[git remote show]["foo"]
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
should "be able to pull from a url instead of a known skeleton" do
|
225
|
+
chdir tmp_path do
|
226
|
+
rm_rf "monk-test"
|
227
|
+
mkdir "monk-test"
|
228
|
+
path = create_template("foo")
|
229
|
+
chdir "monk-test" do
|
230
|
+
out, err = monk("init --skeleton #{path}")
|
231
|
+
assert_match /initialized/, out
|
232
|
+
assert is_template?(".", "foo")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
69
237
|
end
|
70
238
|
|
71
239
|
context "monk show NAME" do
|
72
240
|
should "display the repository for NAME" do
|
73
241
|
out, err = monk("show default")
|
74
|
-
assert out["
|
242
|
+
assert out[template_path "default"]
|
75
243
|
end
|
76
244
|
|
77
245
|
should "display nothing if NAME is not set" do
|
@@ -84,7 +252,7 @@ class TestMonk < Test::Unit::TestCase
|
|
84
252
|
should "display the configured repositories" do
|
85
253
|
out, err = monk("list")
|
86
254
|
assert out["default"]
|
87
|
-
assert out["
|
255
|
+
assert out[template_path "default"]
|
88
256
|
end
|
89
257
|
end
|
90
258
|
|
@@ -98,30 +266,85 @@ class TestMonk < Test::Unit::TestCase
|
|
98
266
|
end
|
99
267
|
|
100
268
|
should "allow to fetch from the added repository when using the skeleton parameter" do
|
101
|
-
|
269
|
+
path = create_template "foo"
|
102
270
|
|
103
|
-
|
104
|
-
|
105
|
-
|
271
|
+
chdir(tmp_path) do
|
272
|
+
rm_rf("monk-test")
|
273
|
+
mkdir("monk-test")
|
106
274
|
|
107
|
-
out, err = monk("init monk-test --skeleton
|
275
|
+
out, err = monk("init monk-test --skeleton foo")
|
108
276
|
assert_match /initialized/, out
|
109
|
-
assert_match
|
277
|
+
assert_match /#{path}/, out
|
278
|
+
assert is_template?("monk-test", "foo")
|
110
279
|
end
|
111
280
|
end
|
112
281
|
|
113
282
|
should "allow to fetch from the added repository when using the s parameter" do
|
114
|
-
|
283
|
+
path = create_template "foo"
|
115
284
|
|
116
|
-
|
117
|
-
|
118
|
-
|
285
|
+
chdir(tmp_path) do
|
286
|
+
rm_rf("monk-test")
|
287
|
+
mkdir("monk-test")
|
119
288
|
|
120
|
-
out, err = monk("init monk-test -s
|
289
|
+
out, err = monk("init monk-test -s foo")
|
121
290
|
assert_match /initialized/, out
|
122
|
-
assert_match
|
291
|
+
assert_match /#{path}/, out
|
292
|
+
assert is_template?("monk-test", "foo")
|
123
293
|
end
|
124
294
|
end
|
295
|
+
|
296
|
+
should "not remove .git if keep-remote option is passed" do
|
297
|
+
chdir tmp_path do
|
298
|
+
rm_rf("monk-test")
|
299
|
+
mkdir("monk-test")
|
300
|
+
create_template "foo", "--keep-remote"
|
301
|
+
|
302
|
+
chdir("monk-test") do
|
303
|
+
out, err = monk("init --skeleton foo")
|
304
|
+
assert_match /initialized/, out
|
305
|
+
assert File.exist?(".git")
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
should "remove .git if no-keep-remote option is passed" do
|
311
|
+
chdir tmp_path do
|
312
|
+
rm_rf("monk-test")
|
313
|
+
mkdir("monk-test")
|
314
|
+
create_template "foo", "--no-keep-remote"
|
315
|
+
|
316
|
+
chdir("monk-test") do
|
317
|
+
out, err = monk("init --skeleton foo")
|
318
|
+
assert_match /initialized/, out
|
319
|
+
assert !File.exist?(".git")
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
should "not remove .git if k option is passed" do
|
325
|
+
chdir tmp_path do
|
326
|
+
rm_rf("monk-test")
|
327
|
+
mkdir("monk-test")
|
328
|
+
create_template "foo", "-k"
|
329
|
+
|
330
|
+
chdir("monk-test") do
|
331
|
+
out, err = monk("init --skeleton foo")
|
332
|
+
assert_match /initialized/, out
|
333
|
+
assert File.exist?(".git")
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
should "name remote after remote-name parameter" do
|
339
|
+
chdir tmp_path do
|
340
|
+
rm_rf "monk-test"
|
341
|
+
create_template "foo", "--keep-remote --remote-name foo"
|
342
|
+
out, err = monk("init monk-test --skeleton foo")
|
343
|
+
assert_match /initialized.* monk-test/, out
|
344
|
+
chdir("monk-test") { assert %x[git remote show]["foo"] }
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
125
348
|
end
|
126
349
|
|
127
350
|
context "monk rm NAME" do
|
@@ -132,4 +355,28 @@ class TestMonk < Test::Unit::TestCase
|
|
132
355
|
assert out["repository not found"]
|
133
356
|
end
|
134
357
|
end
|
358
|
+
|
359
|
+
context "monk copy FROM TO" do
|
360
|
+
should "copy a template" do
|
361
|
+
chdir tmp_path do
|
362
|
+
rm_rf "monk-test"
|
363
|
+
monk "copy default foo"
|
364
|
+
monk "init monk-test -s foo"
|
365
|
+
assert is_template?("monk-test", "default")
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context "monk change NAME" do
|
371
|
+
should "remove the named repository from the configuration" do
|
372
|
+
monk("add foobar git://github.com/monkrb/foo.git --keep-remote")
|
373
|
+
out, err = monk("show foobar")
|
374
|
+
assert out["keep-remote"]
|
375
|
+
assert !out["no-keep-remote"]
|
376
|
+
monk("change foobar --no-keep-remote")
|
377
|
+
out, err = monk("show foobar")
|
378
|
+
assert out["no-keep-remote"]
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
135
382
|
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
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
|
+
include FileUtils
|
15
|
+
|
16
|
+
def root(*args)
|
17
|
+
File.expand_path File.join(ROOT, *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def tmp_path(*args)
|
21
|
+
root("test", "tmp", *args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
mkdir_p tmp_path
|
26
|
+
rm_f tmp_path(".monk")
|
27
|
+
create_template "default"
|
28
|
+
end
|
29
|
+
|
30
|
+
def template_path(name = default)
|
31
|
+
tmp_path("templates", name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_template(name, add = "")
|
35
|
+
dir = template_path(name)
|
36
|
+
mkdir_p dir
|
37
|
+
chdir(dir) do
|
38
|
+
unless File.exist? "name"
|
39
|
+
File.open("name", "w") { |f| f << name }
|
40
|
+
raise RuntimeError, "could not initialize git repo" unless system <<-EOS
|
41
|
+
git init -q &&
|
42
|
+
git add name 2>/dev/null &&
|
43
|
+
git ci -m "created template" -q
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
end
|
47
|
+
monk("add #{name} #{dir} #{add}") if add
|
48
|
+
dir
|
49
|
+
end
|
50
|
+
|
51
|
+
def in_template(name, &block)
|
52
|
+
chdir(create_template(name), &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def is_template?(path, name)
|
56
|
+
file = File.join path, "name"
|
57
|
+
File.exist?(file) && File.read(file) == name
|
58
|
+
end
|
59
|
+
|
60
|
+
def monk(args = nil)
|
61
|
+
sh("env MONK_HOME=#{File.join(ROOT, "test", "tmp")} ruby -rubygems #{root "bin/monk"} #{args}")
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rkh-monk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Janowski
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.0.
|
34
|
+
version: 0.0.7
|
35
35
|
version:
|
36
36
|
description: Monk is a glue framework for web development. It means that instead of installing all the tools you need for your projects, you can rely on a git repository and a list of dependencies, and Monk will care of the rest. By default, it ships with a Sinatra application that includes Contest, Stories, Webrat, Ohm and some other niceties, along with a structure and helpful documentation to get your hands wet in no time.
|
37
37
|
email:
|
@@ -48,14 +48,15 @@ files:
|
|
48
48
|
- README.markdown
|
49
49
|
- Rakefile
|
50
50
|
- bin/monk
|
51
|
+
- lib/monk/skeleton.rb
|
51
52
|
- lib/monk.rb
|
52
53
|
- monk.gemspec
|
53
54
|
- test/commands.rb
|
54
55
|
- test/integration_test.rb
|
55
56
|
- test/monk_test.rb
|
57
|
+
- test/test_helper.rb
|
56
58
|
has_rdoc: false
|
57
59
|
homepage: http://monkrb.com
|
58
|
-
licenses:
|
59
60
|
post_install_message:
|
60
61
|
rdoc_options: []
|
61
62
|
|
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
requirements:
|
77
78
|
- git
|
78
79
|
rubyforge_project: monk
|
79
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.2.0
|
80
81
|
signing_key:
|
81
82
|
specification_version: 2
|
82
83
|
summary: Monk, the glue framework
|