angry_mob 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +123 -0
- data/bin/mob +139 -0
- data/lib/angry_mob.rb +28 -0
- data/lib/angry_mob/act.rb +111 -0
- data/lib/angry_mob/act/scheduler.rb +143 -0
- data/lib/angry_mob/action.rb +11 -0
- data/lib/angry_mob/builder.rb +115 -0
- data/lib/angry_mob/extend.rb +10 -0
- data/lib/angry_mob/extend/array.rb +30 -0
- data/lib/angry_mob/extend/blank.rb +108 -0
- data/lib/angry_mob/extend/blankslate.rb +109 -0
- data/lib/angry_mob/extend/dictionary.rb +140 -0
- data/lib/angry_mob/extend/hash.rb +67 -0
- data/lib/angry_mob/extend/object.rb +21 -0
- data/lib/angry_mob/extend/pathname.rb +23 -0
- data/lib/angry_mob/extend/string.rb +8 -0
- data/lib/angry_mob/log.rb +28 -0
- data/lib/angry_mob/mob.rb +77 -0
- data/lib/angry_mob/mob_loader.rb +115 -0
- data/lib/angry_mob/node.rb +44 -0
- data/lib/angry_mob/notifier.rb +76 -0
- data/lib/angry_mob/target.rb +257 -0
- data/lib/angry_mob/target/arguments.rb +71 -0
- data/lib/angry_mob/target/call.rb +57 -0
- data/lib/angry_mob/target/default_resource_locator.rb +11 -0
- data/lib/angry_mob/target/defaults.rb +23 -0
- data/lib/angry_mob/target/mother.rb +66 -0
- data/lib/angry_mob/target/notify.rb +57 -0
- data/lib/angry_mob/target/tracking.rb +96 -0
- data/lib/angry_mob/ui.rb +247 -0
- data/lib/angry_mob/util.rb +11 -0
- data/lib/angry_mob/vendored.rb +8 -0
- data/lib/angry_mob/version.rb +3 -0
- data/vendor/angry_hash/Rakefile +17 -0
- data/vendor/angry_hash/VERSION +1 -0
- data/vendor/angry_hash/angry_hash.gemspec +47 -0
- data/vendor/angry_hash/examples/accessors_eg.rb +46 -0
- data/vendor/angry_hash/examples/creation_eg.rb +43 -0
- data/vendor/angry_hash/examples/dsl.eg.rb +18 -0
- data/vendor/angry_hash/examples/dup_eg.rb +86 -0
- data/vendor/angry_hash/examples/eg_helper.rb +24 -0
- data/vendor/angry_hash/examples/merge_eg.rb +135 -0
- data/vendor/angry_hash/lib/angry_hash.rb +215 -0
- data/vendor/angry_hash/lib/angry_hash/dsl.rb +44 -0
- data/vendor/angry_hash/lib/angry_hash/extension_tracking.rb +12 -0
- data/vendor/angry_hash/lib/angry_hash/merge_string.rb +58 -0
- data/vendor/json/COPYING +58 -0
- data/vendor/json/GPL +340 -0
- data/vendor/json/README +360 -0
- data/vendor/json/lib/json/common.rb +371 -0
- data/vendor/json/lib/json/pure.rb +77 -0
- data/vendor/json/lib/json/pure/generator.rb +443 -0
- data/vendor/json/lib/json/pure/parser.rb +303 -0
- data/vendor/json/lib/json/version.rb +8 -0
- data/vendor/thor/CHANGELOG.rdoc +89 -0
- data/vendor/thor/LICENSE +20 -0
- data/vendor/thor/README.rdoc +297 -0
- data/vendor/thor/Thorfile +69 -0
- data/vendor/thor/bin/rake2thor +86 -0
- data/vendor/thor/bin/thor +6 -0
- data/vendor/thor/lib/thor.rb +244 -0
- data/vendor/thor/lib/thor/actions.rb +275 -0
- data/vendor/thor/lib/thor/actions/create_file.rb +103 -0
- data/vendor/thor/lib/thor/actions/directory.rb +91 -0
- data/vendor/thor/lib/thor/actions/empty_directory.rb +134 -0
- data/vendor/thor/lib/thor/actions/file_manipulation.rb +223 -0
- data/vendor/thor/lib/thor/actions/inject_into_file.rb +104 -0
- data/vendor/thor/lib/thor/base.rb +540 -0
- data/vendor/thor/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/vendor/thor/lib/thor/error.rb +30 -0
- data/vendor/thor/lib/thor/group.rb +271 -0
- data/vendor/thor/lib/thor/invocation.rb +180 -0
- data/vendor/thor/lib/thor/parser.rb +4 -0
- data/vendor/thor/lib/thor/parser/argument.rb +67 -0
- data/vendor/thor/lib/thor/parser/arguments.rb +150 -0
- data/vendor/thor/lib/thor/parser/option.rb +128 -0
- data/vendor/thor/lib/thor/parser/options.rb +169 -0
- data/vendor/thor/lib/thor/rake_compat.rb +66 -0
- data/vendor/thor/lib/thor/runner.rb +314 -0
- data/vendor/thor/lib/thor/shell.rb +83 -0
- data/vendor/thor/lib/thor/shell/basic.rb +239 -0
- data/vendor/thor/lib/thor/shell/color.rb +108 -0
- data/vendor/thor/lib/thor/task.rb +102 -0
- data/vendor/thor/lib/thor/util.rb +224 -0
- data/vendor/thor/lib/thor/version.rb +3 -0
- data/vendor/thor/spec/actions/create_file_spec.rb +170 -0
- data/vendor/thor/spec/actions/directory_spec.rb +131 -0
- data/vendor/thor/spec/actions/empty_directory_spec.rb +91 -0
- data/vendor/thor/spec/actions/file_manipulation_spec.rb +271 -0
- data/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
- data/vendor/thor/spec/actions_spec.rb +292 -0
- data/vendor/thor/spec/base_spec.rb +263 -0
- data/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
- data/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/vendor/thor/spec/fixtures/application.rb +2 -0
- data/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
- data/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
- data/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/vendor/thor/spec/fixtures/doc/README +3 -0
- data/vendor/thor/spec/fixtures/doc/config.rb +1 -0
- data/vendor/thor/spec/fixtures/group.thor +90 -0
- data/vendor/thor/spec/fixtures/invoke.thor +112 -0
- data/vendor/thor/spec/fixtures/script.thor +145 -0
- data/vendor/thor/spec/fixtures/task.thor +10 -0
- data/vendor/thor/spec/group_spec.rb +171 -0
- data/vendor/thor/spec/invocation_spec.rb +107 -0
- data/vendor/thor/spec/parser/argument_spec.rb +47 -0
- data/vendor/thor/spec/parser/arguments_spec.rb +64 -0
- data/vendor/thor/spec/parser/option_spec.rb +202 -0
- data/vendor/thor/spec/parser/options_spec.rb +292 -0
- data/vendor/thor/spec/rake_compat_spec.rb +68 -0
- data/vendor/thor/spec/runner_spec.rb +210 -0
- data/vendor/thor/spec/shell/basic_spec.rb +205 -0
- data/vendor/thor/spec/shell/color_spec.rb +41 -0
- data/vendor/thor/spec/shell_spec.rb +34 -0
- data/vendor/thor/spec/spec.opts +1 -0
- data/vendor/thor/spec/spec_helper.rb +54 -0
- data/vendor/thor/spec/task_spec.rb +69 -0
- data/vendor/thor/spec/thor_spec.rb +237 -0
- data/vendor/thor/spec/util_spec.rb +163 -0
- data/vendor/thor/thor.gemspec +120 -0
- metadata +199 -0
@@ -0,0 +1,224 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Sandbox #:nodoc:
|
5
|
+
end
|
6
|
+
|
7
|
+
# This module holds several utilities:
|
8
|
+
#
|
9
|
+
# 1) Methods to convert thor namespaces to constants and vice-versa.
|
10
|
+
#
|
11
|
+
# Thor::Utils.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz"
|
12
|
+
#
|
13
|
+
# 2) Loading thor files and sandboxing:
|
14
|
+
#
|
15
|
+
# Thor::Utils.load_thorfile("~/.thor/foo")
|
16
|
+
#
|
17
|
+
module Util
|
18
|
+
|
19
|
+
# Receives a namespace and search for it in the Thor::Base subclasses.
|
20
|
+
#
|
21
|
+
# ==== Parameters
|
22
|
+
# namespace<String>:: The namespace to search for.
|
23
|
+
#
|
24
|
+
def self.find_by_namespace(namespace)
|
25
|
+
namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
|
26
|
+
Thor::Base.subclasses.find { |klass| klass.namespace == namespace }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Receives a constant and converts it to a Thor namespace. Since Thor tasks
|
30
|
+
# can be added to a sandbox, this method is also responsable for removing
|
31
|
+
# the sandbox namespace.
|
32
|
+
#
|
33
|
+
# This method should not be used in general because it's used to deal with
|
34
|
+
# older versions of Thor. On current versions, if you need to get the
|
35
|
+
# namespace from a class, just call namespace on it.
|
36
|
+
#
|
37
|
+
# ==== Parameters
|
38
|
+
# constant<Object>:: The constant to be converted to the thor path.
|
39
|
+
#
|
40
|
+
# ==== Returns
|
41
|
+
# String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz"
|
42
|
+
#
|
43
|
+
def self.namespace_from_thor_class(constant)
|
44
|
+
constant = constant.to_s.gsub(/^Thor::Sandbox::/, "")
|
45
|
+
constant = snake_case(constant).squeeze(":")
|
46
|
+
constant
|
47
|
+
end
|
48
|
+
|
49
|
+
# Given the contents, evaluate it inside the sandbox and returns the
|
50
|
+
# namespaces defined in the sandbox.
|
51
|
+
#
|
52
|
+
# ==== Parameters
|
53
|
+
# contents<String>
|
54
|
+
#
|
55
|
+
# ==== Returns
|
56
|
+
# Array[Object]
|
57
|
+
#
|
58
|
+
def self.namespaces_in_content(contents, file=__FILE__)
|
59
|
+
old_constants = Thor::Base.subclasses.dup
|
60
|
+
Thor::Base.subclasses.clear
|
61
|
+
|
62
|
+
load_thorfile(file, contents)
|
63
|
+
|
64
|
+
new_constants = Thor::Base.subclasses.dup
|
65
|
+
Thor::Base.subclasses.replace(old_constants)
|
66
|
+
|
67
|
+
new_constants.map!{ |c| c.namespace }
|
68
|
+
new_constants.compact!
|
69
|
+
new_constants
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the thor classes declared inside the given class.
|
73
|
+
#
|
74
|
+
def self.thor_classes_in(klass)
|
75
|
+
stringfied_constants = klass.constants.map { |c| c.to_s }
|
76
|
+
Thor::Base.subclasses.select do |subclass|
|
77
|
+
next unless subclass.name
|
78
|
+
stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ''))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Receives a string and convert it to snake case. SnakeCase returns snake_case.
|
83
|
+
#
|
84
|
+
# ==== Parameters
|
85
|
+
# String
|
86
|
+
#
|
87
|
+
# ==== Returns
|
88
|
+
# String
|
89
|
+
#
|
90
|
+
def self.snake_case(str)
|
91
|
+
return str.downcase if str =~ /^[A-Z_]+$/
|
92
|
+
str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
|
93
|
+
return $+.downcase
|
94
|
+
end
|
95
|
+
|
96
|
+
# Receives a string and convert it to camel case. camel_case returns CamelCase.
|
97
|
+
#
|
98
|
+
# ==== Parameters
|
99
|
+
# String
|
100
|
+
#
|
101
|
+
# ==== Returns
|
102
|
+
# String
|
103
|
+
#
|
104
|
+
def self.camel_case(str)
|
105
|
+
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
106
|
+
str.split('_').map { |i| i.capitalize }.join
|
107
|
+
end
|
108
|
+
|
109
|
+
# Receives a namespace and tries to retrieve a Thor or Thor::Group class
|
110
|
+
# from it. It first searches for a class using the all the given namespace,
|
111
|
+
# if it's not found, removes the highest entry and searches for the class
|
112
|
+
# again. If found, returns the highest entry as the class name.
|
113
|
+
#
|
114
|
+
# ==== Examples
|
115
|
+
#
|
116
|
+
# class Foo::Bar < Thor
|
117
|
+
# def baz
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# class Baz::Foo < Thor::Group
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default task
|
125
|
+
# Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
|
126
|
+
# Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
|
127
|
+
#
|
128
|
+
# ==== Parameters
|
129
|
+
# namespace<String>
|
130
|
+
#
|
131
|
+
def self.find_class_and_task_by_namespace(namespace, fallback = true)
|
132
|
+
if namespace.include?(?:) # look for a namespaced task
|
133
|
+
pieces = namespace.split(":")
|
134
|
+
task = pieces.pop
|
135
|
+
klass = Thor::Util.find_by_namespace(pieces.join(":"))
|
136
|
+
end
|
137
|
+
unless klass # look for a Thor::Group with the right name
|
138
|
+
klass, task = Thor::Util.find_by_namespace(namespace), nil
|
139
|
+
end
|
140
|
+
if !klass && fallback # try a task in the default namespace
|
141
|
+
task = namespace
|
142
|
+
klass = Thor::Util.find_by_namespace('')
|
143
|
+
end
|
144
|
+
return klass, task
|
145
|
+
end
|
146
|
+
|
147
|
+
# Receives a path and load the thor file in the path. The file is evaluated
|
148
|
+
# inside the sandbox to avoid namespacing conflicts.
|
149
|
+
#
|
150
|
+
def self.load_thorfile(path, content=nil)
|
151
|
+
content ||= File.binread(path)
|
152
|
+
|
153
|
+
begin
|
154
|
+
Thor::Sandbox.class_eval(content, path)
|
155
|
+
rescue Exception => e
|
156
|
+
$stderr.puts "WARNING: unable to load thorfile #{path.inspect}: #{e.message}"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.user_home
|
161
|
+
@@user_home ||= if ENV["HOME"]
|
162
|
+
ENV["HOME"]
|
163
|
+
elsif ENV["USERPROFILE"]
|
164
|
+
ENV["USERPROFILE"]
|
165
|
+
elsif ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
|
166
|
+
File.join(ENV["HOMEDRIVE"], ENV["HOMEPATH"])
|
167
|
+
elsif ENV["APPDATA"]
|
168
|
+
ENV["APPDATA"]
|
169
|
+
else
|
170
|
+
begin
|
171
|
+
File.expand_path("~")
|
172
|
+
rescue
|
173
|
+
if File::ALT_SEPARATOR
|
174
|
+
"C:/"
|
175
|
+
else
|
176
|
+
"/"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Returns the root where thor files are located, dependending on the OS.
|
183
|
+
#
|
184
|
+
def self.thor_root
|
185
|
+
File.join(user_home, ".thor").gsub(/\\/, '/')
|
186
|
+
end
|
187
|
+
|
188
|
+
# Returns the files in the thor root. On Windows thor_root will be something
|
189
|
+
# like this:
|
190
|
+
#
|
191
|
+
# C:\Documents and Settings\james\.thor
|
192
|
+
#
|
193
|
+
# If we don't #gsub the \ character, Dir.glob will fail.
|
194
|
+
#
|
195
|
+
def self.thor_root_glob
|
196
|
+
files = Dir["#{thor_root}/*"]
|
197
|
+
|
198
|
+
files.map! do |file|
|
199
|
+
File.directory?(file) ? File.join(file, "main.thor") : file
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# Where to look for Thor files.
|
204
|
+
#
|
205
|
+
def self.globs_for(path)
|
206
|
+
["#{path}/Thorfile", "#{path}/*.thor", "#{path}/tasks/*.thor", "#{path}/lib/tasks/*.thor"]
|
207
|
+
end
|
208
|
+
|
209
|
+
# Return the path to the ruby interpreter taking into account multiple
|
210
|
+
# installations and windows extensions.
|
211
|
+
#
|
212
|
+
def self.ruby_command
|
213
|
+
@ruby_command ||= begin
|
214
|
+
ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
215
|
+
ruby << Config::CONFIG['EXEEXT']
|
216
|
+
|
217
|
+
# escape string in case path to ruby executable contain spaces.
|
218
|
+
ruby.sub!(/.*\s.*/m, '"\&"')
|
219
|
+
ruby
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'thor/actions'
|
3
|
+
|
4
|
+
describe Thor::Actions::CreateFile do
|
5
|
+
before(:each) do
|
6
|
+
::FileUtils.rm_rf(destination_root)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_file(destination=nil, config={}, options={})
|
10
|
+
@base = MyCounter.new([1,2], options, { :destination_root => destination_root })
|
11
|
+
@base.stub!(:file_name).and_return('rdoc')
|
12
|
+
|
13
|
+
@action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION",
|
14
|
+
{ :verbose => !@silence }.merge(config))
|
15
|
+
end
|
16
|
+
|
17
|
+
def invoke!
|
18
|
+
capture(:stdout){ @action.invoke! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def revoke!
|
22
|
+
capture(:stdout){ @action.revoke! }
|
23
|
+
end
|
24
|
+
|
25
|
+
def silence!
|
26
|
+
@silence = true
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#invoke!" do
|
30
|
+
it "creates a file" do
|
31
|
+
create_file("doc/config.rb")
|
32
|
+
invoke!
|
33
|
+
File.exists?(File.join(destination_root, "doc/config.rb")).must be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not create a file if pretending" do
|
37
|
+
create_file("doc/config.rb", {}, :pretend => true)
|
38
|
+
invoke!
|
39
|
+
File.exists?(File.join(destination_root, "doc/config.rb")).must be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "shows created status to the user" do
|
43
|
+
create_file("doc/config.rb")
|
44
|
+
invoke!.must == " create doc/config.rb\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not show any information if log status is false" do
|
48
|
+
silence!
|
49
|
+
create_file("doc/config.rb")
|
50
|
+
invoke!.must be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns the given destination" do
|
54
|
+
capture(:stdout) do
|
55
|
+
create_file("doc/config.rb").invoke!.must == "doc/config.rb"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "converts encoded instructions" do
|
60
|
+
create_file("doc/%file_name%.rb.tt")
|
61
|
+
invoke!
|
62
|
+
File.exists?(File.join(destination_root, "doc/rdoc.rb.tt")).must be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when file exists" do
|
66
|
+
before(:each) do
|
67
|
+
create_file("doc/config.rb")
|
68
|
+
invoke!
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "and is identical" do
|
72
|
+
it "shows identical status" do
|
73
|
+
create_file("doc/config.rb")
|
74
|
+
invoke!
|
75
|
+
invoke!.must == " identical doc/config.rb\n"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "and is not identical" do
|
80
|
+
before(:each) do
|
81
|
+
File.open(File.join(destination_root, 'doc/config.rb'), 'w'){ |f| f.write("FOO = 3") }
|
82
|
+
end
|
83
|
+
|
84
|
+
it "shows forced status to the user if force is given" do
|
85
|
+
create_file("doc/config.rb", {}, :force => true).must_not be_identical
|
86
|
+
invoke!.must == " force doc/config.rb\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "shows skipped status to the user if skip is given" do
|
90
|
+
create_file("doc/config.rb", {}, :skip => true).must_not be_identical
|
91
|
+
invoke!.must == " skip doc/config.rb\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "shows forced status to the user if force is configured" do
|
95
|
+
create_file("doc/config.rb", :force => true).must_not be_identical
|
96
|
+
invoke!.must == " force doc/config.rb\n"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "shows skipped status to the user if skip is configured" do
|
100
|
+
create_file("doc/config.rb", :skip => true).must_not be_identical
|
101
|
+
invoke!.must == " skip doc/config.rb\n"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "shows conflict status to ther user" do
|
105
|
+
create_file("doc/config.rb").must_not be_identical
|
106
|
+
$stdin.should_receive(:gets).and_return('s')
|
107
|
+
file = File.join(destination_root, 'doc/config.rb')
|
108
|
+
|
109
|
+
content = invoke!
|
110
|
+
content.must =~ /conflict doc\/config\.rb/
|
111
|
+
content.must =~ /Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/
|
112
|
+
content.must =~ /skip doc\/config\.rb/
|
113
|
+
end
|
114
|
+
|
115
|
+
it "creates the file if the file collision menu returns true" do
|
116
|
+
create_file("doc/config.rb")
|
117
|
+
$stdin.should_receive(:gets).and_return('y')
|
118
|
+
invoke!.must =~ /force doc\/config\.rb/
|
119
|
+
end
|
120
|
+
|
121
|
+
it "skips the file if the file collision menu returns false" do
|
122
|
+
create_file("doc/config.rb")
|
123
|
+
$stdin.should_receive(:gets).and_return('n')
|
124
|
+
invoke!.must =~ /skip doc\/config\.rb/
|
125
|
+
end
|
126
|
+
|
127
|
+
it "executes the block given to show file content" do
|
128
|
+
create_file("doc/config.rb")
|
129
|
+
$stdin.should_receive(:gets).and_return('d')
|
130
|
+
$stdin.should_receive(:gets).and_return('n')
|
131
|
+
@base.shell.should_receive(:system).with(/diff -u/)
|
132
|
+
invoke!
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#revoke!" do
|
139
|
+
it "removes the destination file" do
|
140
|
+
create_file("doc/config.rb")
|
141
|
+
invoke!
|
142
|
+
revoke!
|
143
|
+
File.exists?(@action.destination).must be_false
|
144
|
+
end
|
145
|
+
|
146
|
+
it "does not raise an error if the file does not exist" do
|
147
|
+
create_file("doc/config.rb")
|
148
|
+
revoke!
|
149
|
+
File.exists?(@action.destination).must be_false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#exists?" do
|
154
|
+
it "returns true if the destination file exists" do
|
155
|
+
create_file("doc/config.rb")
|
156
|
+
@action.exists?.must be_false
|
157
|
+
invoke!
|
158
|
+
@action.exists?.must be_true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "#identical?" do
|
163
|
+
it "returns true if the destination file and is identical" do
|
164
|
+
create_file("doc/config.rb")
|
165
|
+
@action.identical?.must be_false
|
166
|
+
invoke!
|
167
|
+
@action.identical?.must be_true
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'thor/actions'
|
3
|
+
|
4
|
+
describe Thor::Actions::Directory do
|
5
|
+
before(:each) do
|
6
|
+
::FileUtils.rm_rf(destination_root)
|
7
|
+
invoker.stub!(:file_name).and_return("rdoc")
|
8
|
+
end
|
9
|
+
|
10
|
+
def invoker
|
11
|
+
@invoker ||= WhinyGenerator.new([1,2], {}, { :destination_root => destination_root })
|
12
|
+
end
|
13
|
+
|
14
|
+
def revoker
|
15
|
+
@revoker ||= WhinyGenerator.new([1,2], {}, { :destination_root => destination_root, :behavior => :revoke })
|
16
|
+
end
|
17
|
+
|
18
|
+
def invoke!(*args, &block)
|
19
|
+
capture(:stdout){ invoker.directory(*args, &block) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def revoke!(*args, &block)
|
23
|
+
capture(:stdout){ revoker.directory(*args, &block) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def exists_and_identical?(source_path, destination_path)
|
27
|
+
%w(config.rb README).each do |file|
|
28
|
+
source = File.join(source_root, source_path, file)
|
29
|
+
destination = File.join(destination_root, destination_path, file)
|
30
|
+
|
31
|
+
File.exists?(destination).must be_true
|
32
|
+
FileUtils.identical?(source, destination).must be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#invoke!" do
|
37
|
+
it "raises an error if the source does not exist" do
|
38
|
+
lambda {
|
39
|
+
invoke! "unknown"
|
40
|
+
}.must raise_error(Thor::Error, /Could not find "unknown" in source paths/)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "copies the whole directory recursively to the default destination" do
|
44
|
+
invoke! "doc"
|
45
|
+
exists_and_identical?("doc", "doc")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "copies the whole directory recursively to the specified destination" do
|
49
|
+
invoke! "doc", "docs"
|
50
|
+
exists_and_identical?("doc", "docs")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "copies only the first level files if recursive" do
|
54
|
+
invoke! ".", "tasks", :recursive => false
|
55
|
+
|
56
|
+
file = File.join(destination_root, "tasks", "group.thor")
|
57
|
+
File.exists?(file).must be_true
|
58
|
+
|
59
|
+
file = File.join(destination_root, "tasks", "doc")
|
60
|
+
File.exists?(file).must be_false
|
61
|
+
|
62
|
+
file = File.join(destination_root, "tasks", "doc", "README")
|
63
|
+
File.exists?(file).must be_false
|
64
|
+
end
|
65
|
+
|
66
|
+
it "copies files from the source relative to the current path" do
|
67
|
+
invoker.inside "doc" do
|
68
|
+
invoke! "."
|
69
|
+
end
|
70
|
+
exists_and_identical?("doc", "doc")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "copies and evaluates templates" do
|
74
|
+
invoke! "doc", "docs"
|
75
|
+
file = File.join(destination_root, "docs", "rdoc.rb")
|
76
|
+
File.exists?(file).must be_true
|
77
|
+
File.read(file).must == "FOO = FOO\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "copies directories" do
|
81
|
+
invoke! "doc", "docs"
|
82
|
+
file = File.join(destination_root, "docs", "components")
|
83
|
+
File.exists?(file).must be_true
|
84
|
+
File.directory?(file).must be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it "does not copy .empty_diretories files" do
|
88
|
+
invoke! "doc", "docs"
|
89
|
+
file = File.join(destination_root, "docs", "components", ".empty_directory")
|
90
|
+
File.exists?(file).must be_false
|
91
|
+
end
|
92
|
+
|
93
|
+
it "copies directories even if they are empty" do
|
94
|
+
invoke! "doc/components", "docs/components"
|
95
|
+
file = File.join(destination_root, "docs", "components")
|
96
|
+
File.exists?(file).must be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "does not copy empty directories twice" do
|
100
|
+
content = invoke!("doc/components", "docs/components")
|
101
|
+
content.must_not =~ /exist/
|
102
|
+
end
|
103
|
+
|
104
|
+
it "logs status" do
|
105
|
+
content = invoke!("doc")
|
106
|
+
content.must =~ /create doc\/README/
|
107
|
+
content.must =~ /create doc\/config\.rb/
|
108
|
+
content.must =~ /create doc\/rdoc\.rb/
|
109
|
+
content.must =~ /create doc\/components/
|
110
|
+
end
|
111
|
+
|
112
|
+
it "yields a block" do
|
113
|
+
checked = false
|
114
|
+
invoke!("doc") do |content|
|
115
|
+
checked ||= !!(content =~ /FOO/)
|
116
|
+
end
|
117
|
+
checked.must be_true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#revoke!" do
|
122
|
+
it "removes the destination file" do
|
123
|
+
invoke! "doc"
|
124
|
+
revoke! "doc"
|
125
|
+
|
126
|
+
File.exists?(File.join(destination_root, "doc", "README")).must be_false
|
127
|
+
File.exists?(File.join(destination_root, "doc", "config.rb")).must be_false
|
128
|
+
File.exists?(File.join(destination_root, "doc", "components")).must be_false
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|