priest 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008 Michel Martens, Damian Janowski and Konstantin Haase
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ Monk
2
+ ====
3
+
4
+ The glue framework for web development.
5
+
6
+ Description
7
+ -----------
8
+
9
+ Monk is a glue framework for web development. It means that instead of
10
+ installing all the tools you need for your projects, you can rely on a
11
+ git repository and a list of dependencies, and Monk takes care of the
12
+ rest. By default, it ships with a Sinatra application that includes
13
+ Contest, Stories, Webrat, Ohm and some other niceties, along with a
14
+ structure and helpful documentation to get your hands wet in no time.
15
+
16
+ But Monk also respects your tastes, and you are invited to create your
17
+ own versions of the skeleton app and your own list of dependencies. You
18
+ can add many different templates (different git repositories) and Monk
19
+ will help you manage them all.
20
+
21
+ Priest is an extended monk commandline tool with functionallity not being
22
+ accepted into mainline monk. It is however compatible with mainline glue
23
+ and skeletons.
24
+
25
+ Usage
26
+ -----
27
+
28
+ Install the monk gem and create your project:
29
+
30
+ $ sudo gem install rkh-priest
31
+ $ priest init myapp
32
+ $ cd myapp
33
+ $ rake
34
+
35
+ If the tests pass, it means that you can start hacking right away. If
36
+ they don't, just follow the instructions. As the default skeleton
37
+ is very opinionated, you will probably need to install and run
38
+ [Redis](http://code.google.com/p/redis/), a key-value database.
39
+
40
+ Check the `dependencies` file in the root of your project to see what
41
+ else is there. Monk works with git almost exclusively, but your project
42
+ can also depend on gems. Check the dependencies file to see what options
43
+ you have, and run the `dep` command line tool to verify it.
44
+
45
+ Installation
46
+ ------------
47
+
48
+ $ sudo gem install rkh-monk
49
+
50
+ License
51
+ -------
52
+
53
+ Copyright (c) 2009 Michel Martens, Damian Janowski and Konstantin Haase
54
+
55
+ Permission is hereby granted, free of charge, to any person
56
+ obtaining a copy of this software and associated documentation
57
+ files (the "Software"), to deal in the Software without
58
+ restriction, including without limitation the rights to use,
59
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
60
+ copies of the Software, and to permit persons to whom the
61
+ Software is furnished to do so, subject to the following
62
+ conditions:
63
+
64
+ The above copyright notice and this permission notice shall be
65
+ included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
68
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
69
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
70
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
71
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
72
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
73
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
74
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ task :test do
2
+ system "cd test && mkdir -p tmp && ruby monk_test.rb"
3
+ end
4
+
5
+ task :default => :test
6
+
7
+ namespace :test do
8
+ task :integration do
9
+ system "cd test && ruby integration_test.rb"
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby -rubygems
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
+ require "monk"
5
+
6
+ # A way to extend Monk is to write tasks in a Monkfile in the project's root directory.
7
+ # Monk loads the Monkfile if there is one, and all the tasks that are declared in the
8
+ # class Monk become available.
9
+ Dir.glob("{Thor,Monk}file") { |f| load f }
10
+
11
+ # Start the monk tasks.
12
+ Monk.start
@@ -0,0 +1,170 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "yaml"
5
+
6
+ require "monk/skeleton"
7
+
8
+ class Monk < Thor
9
+ include Thor::Actions
10
+
11
+ class_options[:skip].aliases.delete "-s" if class_options.include? :skip
12
+
13
+ def self.git_option(name, options = {})
14
+ class_option name, options.merge(:group => :git)
15
+ git_options << name.to_s
16
+ end
17
+
18
+ def self.git_options
19
+ @git_options ||= ["mirror_path"]
20
+ end
21
+
22
+ def self.monk_home
23
+ ENV["MONK_HOME"] || File.join(Thor::Util.user_home)
24
+ end
25
+
26
+ def self.monk_mirrors
27
+ File.join(monk_home, ".monk_mirrors")
28
+ end
29
+
30
+ git_option :branch, :type => :string, :aliases => "-b",
31
+ :desc => "Specify skeleton branch to use."
32
+ git_option :keep_remote, :type => :boolean, :aliases => "-k",
33
+ :desc => "Do not remove .git folder and keep skeleton as remote"
34
+ git_option :remote_name, :type => :string, :aliases => "-r",
35
+ :desc => "Remote name to use for the skeleton. Default is skeleton"
36
+ git_option :mirror, :type => :boolean, :aliases => "-m",
37
+ :desc => "Keep local mirror of the skeleton. For offline use and frequent project creation"
38
+
39
+ desc "init", "Initialize a Monk application. Will try to update mirror for given skeleton."
40
+ method_option :skeleton, :type => :string, :aliases => "-s"
41
+ def init(target = ".")
42
+ say_status :fetching, skeleton.url
43
+ skeleton.create(target) ?
44
+ say_status(:initialized, target) :
45
+ say_status(:error, clone_error(target))
46
+ end
47
+
48
+ desc "show NAME", "Display the repository address for NAME"
49
+ def show(name)
50
+ say_status name, monk_config[name] ? skeleton(name).description : "repository not found"
51
+ end
52
+
53
+ desc "list", "Lists the configured repositories"
54
+ def list
55
+ monk_config.keys.sort.each { |key| show(key) }
56
+ end
57
+
58
+ desc "add NAME REPOSITORY_URL", "Add the repository to the configuration file"
59
+ def add(name, repository_url)
60
+ monk_config[name] = Skeleton.new(repository_url)
61
+ monk_config[name].merge! git_options
62
+ monk_config[name].update_mirror
63
+ write_monk_config_file
64
+ say_status :added, name
65
+ end
66
+
67
+ desc "change NAME", "Modifies options for a repository without having to repeat the url"
68
+ def change(name)
69
+ if monk_config.include? name
70
+ monk_config[name].merge! git_options
71
+ if options.include? "mirror" and not options.mirror?
72
+ path = monk_config[name].delete "mirror_path"
73
+ system "rm -R #{path}" if path
74
+ end
75
+ write_monk_config_file
76
+ say_status :modified, name
77
+ else
78
+ say_status name, "repository not found"
79
+ end
80
+ end
81
+
82
+ desc "rm NAME", "Remove the repository from the configuration file"
83
+ def rm(name)
84
+ skel = monk_config.delete(name)
85
+ write_monk_config_file
86
+ system "rm -R #{skel.mirror_path}" if skel.mirror_path?
87
+ say_status :deleted, name
88
+ end
89
+
90
+ desc "copy FROM TO", "Creates a copy of an existing skeleton"
91
+ def copy(from, to)
92
+ return unless monk_config.include? from
93
+ monk_config[to] = skeleton(from)
94
+ monk_config[to].delete "mirror_path"
95
+ write_monk_config_file
96
+ say_status :added, to
97
+ end
98
+
99
+ desc "cleanup", "Removes mirrors no longer used (or all mirrors with --all)"
100
+ method_option :all, :type => :boolean, :aliases => "-a"
101
+ def cleanup
102
+ say_status "scanning", "mirrors"
103
+ mirrors = Dir.glob File.join(Monk.monk_mirrors, "*")
104
+ monk_config.each_value do |skel|
105
+ mirrors.delete skel.mirror_path if skel.mirror_path?
106
+ end unless options["all"]
107
+ say_status "cleanup", "mirrors"
108
+ system "rm -R #{mirrors.join " "}"
109
+ end
110
+
111
+ desc "update", "Updates all mirrors or mirrors for given skeleton."
112
+ def update(name = nil)
113
+ name ||= options[:skeleton]
114
+ return monk_config.each_key { |s| update(s) } unless name
115
+ skel = skeleton(name)
116
+ if skel.mirror?
117
+ say_status "update", name
118
+ skel.update_mirror
119
+ end
120
+ end
121
+
122
+
123
+ private
124
+
125
+ def skeleton(name = nil)
126
+ name ||= options[:skeleton] || "default"
127
+ (monk_config[name] || Skeleton.new(name)).merge git_options
128
+ end
129
+
130
+ def git_options
131
+ self.class.git_options.inject({}) do |opts, key|
132
+ opts.merge! key => options[key] if options.include? key
133
+ opts
134
+ end
135
+ end
136
+
137
+ def monk_config_file
138
+ @monk_config_file ||= File.join(monk_home, ".monk")
139
+ end
140
+
141
+ def monk_config
142
+ @monk_config ||= begin
143
+ write_monk_config_file unless File.exists? monk_config_file
144
+ YAML.load_file(monk_config_file).inject({}) do |config, (key, value)|
145
+ config.merge key => Skeleton.new(value)
146
+ end
147
+ end
148
+ end
149
+
150
+ def write_monk_config_file
151
+ remove_file monk_config_file, :verbose => false
152
+ create_file(monk_config_file, nil, :verbose => false) do
153
+ config = @monk_config || { "default" => Skeleton.new("git://github.com/monkrb/skeleton.git") }
154
+ config.to_yaml
155
+ end
156
+ end
157
+
158
+ def self.source_root
159
+ "."
160
+ end
161
+
162
+ def clone_error(target)
163
+ "Couldn't clone repository into target directory '#{target}'. " +
164
+ "You must have git installed and the target directory must be empty."
165
+ end
166
+
167
+ def monk_home
168
+ self.class.monk_home
169
+ end
170
+ end
@@ -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
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "priest"
3
+ s.version = "0.0.7"
4
+ s.summary = "Priest, the command line tool for monk."
5
+ s.description = "Priest is a more advanced replacement for the monk command line tool. 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
+ s.authors = ["Konstantin Haase"]
7
+ s.email = ["konstantin.mailinglists@googlemail.com"]
8
+ s.homepage = "http://github.com/rkh/priest"
9
+
10
+ # s.rubyforge_project = "monk"
11
+
12
+ s.executables << "priest"
13
+
14
+ s.add_dependency("thor", "~> 0.11")
15
+ s.add_dependency("dependencies", ">= 0.0.7")
16
+ s.requirements << "git"
17
+
18
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "bin/priest", "lib/monk/skeleton.rb", "lib/monk.rb", "priest.gemspec", "test/commands.rb", "test/integration_test.rb", "test/monk_test.rb", "test/test_helper.rb"]
19
+ end
@@ -0,0 +1,72 @@
1
+ require "open3"
2
+ require "socket"
3
+
4
+ module Test::Commands
5
+ def sh(cmd)
6
+ out, err = nil
7
+
8
+ Open3.popen3(cmd) do |_in, _out, _err|
9
+ out = _out.read
10
+ err = _err.read
11
+ end
12
+
13
+ [out, err]
14
+ end
15
+
16
+ # Runs a command in the background, silencing all output.
17
+ # For debugging purposes, set the environment variable VERBOSE.
18
+ def sh_bg(cmd)
19
+ if ENV["VERBOSE"]
20
+ streams_to_silence = []
21
+ else
22
+ streams_to_silence = [$stdout, $stderr]
23
+ cmd = "#{cmd} 2>&1>/dev/null"
24
+ end
25
+
26
+ silence_stream(*streams_to_silence) do
27
+ (pid = fork) ? Process.detach(pid) : exec(cmd)
28
+ end
29
+ end
30
+
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
+ def silence_stream(*streams) #:yeild:
61
+ on_hold = streams.collect{ |stream| stream.dup }
62
+ streams.each do |stream|
63
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
64
+ stream.sync = true
65
+ end
66
+ yield
67
+ ensure
68
+ streams.each_with_index do |stream, i|
69
+ stream.reopen(on_hold[i])
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,115 @@
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
@@ -0,0 +1,382 @@
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
+ chdir tmp_path do
7
+ rm_rf("monk-test")
8
+ mkdir("monk-test")
9
+
10
+ chdir("monk-test") do
11
+ 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
+ chdir tmp_path do
21
+ rm_rf("monk-test")
22
+
23
+ out, err = monk("init monk-test")
24
+ assert_match /initialized.* monk-test/, out
25
+ assert is_template?("monk-test", "default")
26
+ end
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
+
128
+ end
129
+
130
+ context "monk init" do
131
+ should "fail if the current working directory is not empty" do
132
+ chdir tmp_path do
133
+ rm_rf("monk-test")
134
+ mkdir("monk-test")
135
+
136
+
137
+ chdir("monk-test") do
138
+ touch("foobar")
139
+ out, err = monk("init")
140
+ assert_match /error/, out
141
+ end
142
+ end
143
+ end
144
+
145
+ should "create a skeleton app in the working directory" do
146
+ chdir tmp_path do
147
+ rm_rf("monk-test")
148
+ mkdir("monk-test")
149
+
150
+ chdir("monk-test") do
151
+ out, err = monk("init")
152
+ assert_match /initialized/, out
153
+ assert is_template?(".", "default")
154
+ end
155
+ end
156
+ end
157
+
158
+ should "use an alternative skeleton if the option is provided" do
159
+ chdir tmp_path do
160
+ rm_rf("monk-test")
161
+ mkdir("monk-test")
162
+
163
+ create_template "foobar"
164
+
165
+ chdir("monk-test") do
166
+ out, err = monk("init -s foobar")
167
+ assert_match /initialized/, out
168
+ assert is_template?(".", "foobar")
169
+ end
170
+ end
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
+
237
+ end
238
+
239
+ context "monk show NAME" do
240
+ should "display the repository for NAME" do
241
+ out, err = monk("show default")
242
+ assert out[template_path "default"]
243
+ end
244
+
245
+ should "display nothing if NAME is not set" do
246
+ out, err = monk("show foobar")
247
+ assert out["repository not found"]
248
+ end
249
+ end
250
+
251
+ context "monk list" do
252
+ should "display the configured repositories" do
253
+ out, err = monk("list")
254
+ assert out["default"]
255
+ assert out[template_path "default"]
256
+ end
257
+ end
258
+
259
+ context "monk add NAME REPOSITORY" do
260
+ should "add the named repository to the configuration" do
261
+ monk("add foobar git://github.com/monkrb/foo.git")
262
+ out, err = monk("show foobar")
263
+ assert out["foobar"]
264
+ assert out["git://github.com/monkrb/foo.git"]
265
+ monk("rm foobar")
266
+ end
267
+
268
+ should "allow to fetch from the added repository when using the skeleton parameter" do
269
+ path = create_template "foo"
270
+
271
+ chdir(tmp_path) do
272
+ rm_rf("monk-test")
273
+ mkdir("monk-test")
274
+
275
+ out, err = monk("init monk-test --skeleton foo")
276
+ assert_match /initialized/, out
277
+ assert_match /#{path}/, out
278
+ assert is_template?("monk-test", "foo")
279
+ end
280
+ end
281
+
282
+ should "allow to fetch from the added repository when using the s parameter" do
283
+ path = create_template "foo"
284
+
285
+ chdir(tmp_path) do
286
+ rm_rf("monk-test")
287
+ mkdir("monk-test")
288
+
289
+ out, err = monk("init monk-test -s foo")
290
+ assert_match /initialized/, out
291
+ assert_match /#{path}/, out
292
+ assert is_template?("monk-test", "foo")
293
+ end
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
+
348
+ end
349
+
350
+ context "monk rm NAME" do
351
+ should "remove the named repository from the configuration" do
352
+ monk("add foobar git://github.com/monkrb/foo.git")
353
+ monk("rm foobar")
354
+ out, err = monk("show foobar")
355
+ assert out["repository not found"]
356
+ end
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
+
382
+ end
@@ -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 ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: priest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-14 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "0.11"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: dependencies
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.7
34
+ version:
35
+ description: Priest is a more advanced replacement for the monk command line tool. 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.
36
+ email:
37
+ - konstantin.mailinglists@googlemail.com
38
+ executables:
39
+ - priest
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - LICENSE
46
+ - README.markdown
47
+ - Rakefile
48
+ - bin/priest
49
+ - lib/monk/skeleton.rb
50
+ - lib/monk.rb
51
+ - priest.gemspec
52
+ - test/commands.rb
53
+ - test/integration_test.rb
54
+ - test/monk_test.rb
55
+ - test/test_helper.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/rkh/priest
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements:
78
+ - git
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Priest, the command line tool for monk.
84
+ test_files: []
85
+