millisami-thor 0.14.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +8 -0
- data/.gemtest +0 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/CHANGELOG.rdoc +103 -0
- data/Gemfile +11 -0
- data/LICENSE.md +20 -0
- data/README.md +26 -0
- data/Thorfile +13 -0
- data/bin/rake2thor +86 -0
- data/bin/thor +6 -0
- data/lib/thor/actions/create_file.rb +105 -0
- data/lib/thor/actions/create_link.rb +57 -0
- data/lib/thor/actions/directory.rb +93 -0
- data/lib/thor/actions/empty_directory.rb +134 -0
- data/lib/thor/actions/file_manipulation.rb +270 -0
- data/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/thor/actions.rb +314 -0
- data/lib/thor/base.rb +598 -0
- data/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/thor/error.rb +30 -0
- data/lib/thor/group.rb +276 -0
- data/lib/thor/invocation.rb +168 -0
- data/lib/thor/parser/argument.rb +67 -0
- data/lib/thor/parser/arguments.rb +165 -0
- data/lib/thor/parser/option.rb +120 -0
- data/lib/thor/parser/options.rb +181 -0
- data/lib/thor/parser.rb +4 -0
- data/lib/thor/rake_compat.rb +70 -0
- data/lib/thor/runner.rb +309 -0
- data/lib/thor/shell/basic.rb +302 -0
- data/lib/thor/shell/color.rb +108 -0
- data/lib/thor/shell/html.rb +121 -0
- data/lib/thor/shell.rb +88 -0
- data/lib/thor/task.rb +129 -0
- data/lib/thor/util.rb +229 -0
- data/lib/thor/version.rb +3 -0
- data/lib/thor.rb +336 -0
- data/spec/actions/create_file_spec.rb +170 -0
- data/spec/actions/directory_spec.rb +136 -0
- data/spec/actions/empty_directory_spec.rb +98 -0
- data/spec/actions/file_manipulation_spec.rb +317 -0
- data/spec/actions/inject_into_file_spec.rb +135 -0
- data/spec/actions_spec.rb +322 -0
- data/spec/base_spec.rb +274 -0
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
- data/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/spec/fixtures/application.rb +2 -0
- data/spec/fixtures/bundle/execute.rb +6 -0
- data/spec/fixtures/bundle/main.thor +1 -0
- data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/spec/fixtures/doc/README +3 -0
- data/spec/fixtures/doc/block_helper.rb +3 -0
- data/spec/fixtures/doc/components/.empty_directory +0 -0
- data/spec/fixtures/doc/config.rb +1 -0
- data/spec/fixtures/doc/config.yaml.tt +1 -0
- data/spec/fixtures/group.thor +114 -0
- data/spec/fixtures/invoke.thor +112 -0
- data/spec/fixtures/path with spaces +0 -0
- data/spec/fixtures/script.thor +184 -0
- data/spec/fixtures/task.thor +10 -0
- data/spec/group_spec.rb +216 -0
- data/spec/invocation_spec.rb +100 -0
- data/spec/parser/argument_spec.rb +47 -0
- data/spec/parser/arguments_spec.rb +65 -0
- data/spec/parser/option_spec.rb +202 -0
- data/spec/parser/options_spec.rb +329 -0
- data/spec/rake_compat_spec.rb +72 -0
- data/spec/register_spec.rb +92 -0
- data/spec/runner_spec.rb +210 -0
- data/spec/shell/basic_spec.rb +223 -0
- data/spec/shell/color_spec.rb +41 -0
- data/spec/shell/html_spec.rb +27 -0
- data/spec/shell_spec.rb +47 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/task_spec.rb +74 -0
- data/spec/thor_spec.rb +362 -0
- data/spec/util_spec.rb +163 -0
- data/thor.gemspec +25 -0
- metadata +241 -0
data/spec/thor_spec.rb
ADDED
@@ -0,0 +1,362 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Thor do
|
4
|
+
describe "#method_option" do
|
5
|
+
it "sets options to the next method to be invoked" do
|
6
|
+
args = ["foo", "bar", "--force"]
|
7
|
+
arg, options = MyScript.start(args)
|
8
|
+
options.should == { "force" => true }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ":lazy_default" do
|
12
|
+
it "is absent when option is not specified" do
|
13
|
+
arg, options = MyScript.start(["with_optional"])
|
14
|
+
options.should == {}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets a default that can be overridden for strings" do
|
18
|
+
arg, options = MyScript.start(["with_optional", "--lazy"])
|
19
|
+
options.should == { "lazy" => "yes" }
|
20
|
+
|
21
|
+
arg, options = MyScript.start(["with_optional", "--lazy", "yesyes!"])
|
22
|
+
options.should == { "lazy" => "yesyes!" }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets a default that can be overridden for numerics" do
|
26
|
+
arg, options = MyScript.start(["with_optional", "--lazy-numeric"])
|
27
|
+
options.should == { "lazy_numeric" => 42 }
|
28
|
+
|
29
|
+
arg, options = MyScript.start(["with_optional", "--lazy-numeric", 20000])
|
30
|
+
options.should == { "lazy_numeric" => 20000 }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets a default that can be overridden for arrays" do
|
34
|
+
arg, options = MyScript.start(["with_optional", "--lazy-array"])
|
35
|
+
options.should == { "lazy_array" => %w[eat at joes] }
|
36
|
+
|
37
|
+
arg, options = MyScript.start(["with_optional", "--lazy-array", "hello", "there"])
|
38
|
+
options.should == { "lazy_array" => %w[hello there] }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets a default that can be overridden for hashes" do
|
42
|
+
arg, options = MyScript.start(["with_optional", "--lazy-hash"])
|
43
|
+
options.should == { "lazy_hash" => {'swedish' => 'meatballs'} }
|
44
|
+
|
45
|
+
arg, options = MyScript.start(["with_optional", "--lazy-hash", "polish:sausage"])
|
46
|
+
options.should == { "lazy_hash" => {'polish' => 'sausage'} }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "when :for is supplied" do
|
51
|
+
it "updates an already defined task" do
|
52
|
+
args, options = MyChildScript.start(["animal", "horse", "--other=fish"])
|
53
|
+
options[:other].should == "fish"
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "and the target is on the parent class" do
|
57
|
+
it "updates an already defined task" do
|
58
|
+
args = ["example_default_task", "my_param", "--new-option=verified"]
|
59
|
+
options = Scripts::MyScript.start(args)
|
60
|
+
options[:new_option].should == "verified"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "adds a task to the tasks list if the updated task is on the parent class" do
|
64
|
+
Scripts::MyScript.tasks["example_default_task"].should be
|
65
|
+
end
|
66
|
+
|
67
|
+
it "clones the parent task" do
|
68
|
+
Scripts::MyScript.tasks["example_default_task"].should_not == MyChildScript.tasks["example_default_task"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#default_task" do
|
75
|
+
it "sets a default task" do
|
76
|
+
MyScript.default_task.should == "example_default_task"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "invokes the default task if no command is specified" do
|
80
|
+
MyScript.start([]).should == "default task"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "invokes the default task if no command is specified even if switches are given" do
|
84
|
+
MyScript.start(["--with", "option"]).should == {"with"=>"option"}
|
85
|
+
end
|
86
|
+
|
87
|
+
it "inherits the default task from parent" do
|
88
|
+
MyChildScript.default_task.should == "example_default_task"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#map" do
|
93
|
+
it "calls the alias of a method if one is provided" do
|
94
|
+
MyScript.start(["-T", "fish"]).should == ["fish"]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "calls the alias of a method if several are provided via .map" do
|
98
|
+
MyScript.start(["-f", "fish"]).should == ["fish", {}]
|
99
|
+
MyScript.start(["--foo", "fish"]).should == ["fish", {}]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "inherits all mappings from parent" do
|
103
|
+
MyChildScript.default_task.should == "example_default_task"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#desc" do
|
108
|
+
it "provides description for a task" do
|
109
|
+
content = capture(:stdout) { MyScript.start(["help"]) }
|
110
|
+
content.should =~ /thor my_script:zoo\s+# zoo around/m
|
111
|
+
end
|
112
|
+
|
113
|
+
it "provides no namespace if $thor_runner is false" do
|
114
|
+
begin
|
115
|
+
$thor_runner = false
|
116
|
+
content = capture(:stdout) { MyScript.start(["help"]) }
|
117
|
+
content.should =~ /thor zoo\s+# zoo around/m
|
118
|
+
ensure
|
119
|
+
$thor_runner = true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "when :for is supplied" do
|
124
|
+
it "overwrites a previous defined task" do
|
125
|
+
capture(:stdout) { MyChildScript.start(["help"]) }.should =~ /animal KIND \s+# fish around/m
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "when :hide is supplied" do
|
130
|
+
it "does not show the task in help" do
|
131
|
+
capture(:stdout) { MyScript.start(["help"]) }.should_not =~ /this is hidden/m
|
132
|
+
end
|
133
|
+
|
134
|
+
it "but the task is still invokcable not show the task in help" do
|
135
|
+
MyScript.start(["hidden", "yesyes"]).should == ["yesyes"]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#method_options" do
|
141
|
+
it "sets default options if called before an initializer" do
|
142
|
+
options = MyChildScript.class_options
|
143
|
+
options[:force].type.should == :boolean
|
144
|
+
options[:param].type.should == :numeric
|
145
|
+
end
|
146
|
+
|
147
|
+
it "overwrites default options if called on the method scope" do
|
148
|
+
args = ["zoo", "--force", "--param", "feathers"]
|
149
|
+
options = MyChildScript.start(args)
|
150
|
+
options.should == { "force" => true, "param" => "feathers" }
|
151
|
+
end
|
152
|
+
|
153
|
+
it "allows default options to be merged with method options" do
|
154
|
+
args = ["animal", "bird", "--force", "--param", "1.0", "--other", "tweets"]
|
155
|
+
arg, options = MyChildScript.start(args)
|
156
|
+
arg.should == 'bird'
|
157
|
+
options.should == { "force"=>true, "param"=>1.0, "other"=>"tweets" }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#start" do
|
162
|
+
it "calls a no-param method when no params are passed" do
|
163
|
+
MyScript.start(["zoo"]).should == true
|
164
|
+
end
|
165
|
+
|
166
|
+
it "calls a single-param method when a single param is passed" do
|
167
|
+
MyScript.start(["animal", "fish"]).should == ["fish"]
|
168
|
+
end
|
169
|
+
|
170
|
+
it "does not set options in attributes" do
|
171
|
+
MyScript.start(["with_optional", "--all"]).should == [nil, { "all" => true }, []]
|
172
|
+
end
|
173
|
+
|
174
|
+
it "raises an error if a required param is not provided" do
|
175
|
+
capture(:stderr) { MyScript.start(["animal"]) }.strip.should == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".'
|
176
|
+
end
|
177
|
+
|
178
|
+
it "raises an error if the invoked task does not exist" do
|
179
|
+
capture(:stderr) { Amazing.start(["animal"]) }.strip.should == 'Could not find task "animal" in "amazing" namespace.'
|
180
|
+
end
|
181
|
+
|
182
|
+
it "calls method_missing if an unknown method is passed in" do
|
183
|
+
MyScript.start(["unk", "hello"]).should == [:unk, ["hello"]]
|
184
|
+
end
|
185
|
+
|
186
|
+
it "does not call a private method no matter what" do
|
187
|
+
capture(:stderr) { MyScript.start(["what"]) }.strip.should == 'Could not find task "what" in "my_script" namespace.'
|
188
|
+
end
|
189
|
+
|
190
|
+
it "uses task default options" do
|
191
|
+
options = MyChildScript.start(["animal", "fish"]).last
|
192
|
+
options.should == { "other" => "method default" }
|
193
|
+
end
|
194
|
+
|
195
|
+
it "raises when an exception happens within the task call" do
|
196
|
+
lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.should raise_error(ArgumentError)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "#subcommand" do
|
201
|
+
it "maps a given subcommand to another Thor subclass" do
|
202
|
+
barn_help = capture(:stdout){ Scripts::MyDefaults.start(["barn"]) }
|
203
|
+
barn_help.should include("barn help [COMMAND] # Describe subcommands or one specific subcommand")
|
204
|
+
end
|
205
|
+
|
206
|
+
it "passes commands to subcommand classes" do
|
207
|
+
capture(:stdout){ Scripts::MyDefaults.start(["barn", "open"]) }.strip.should == "Open sesame!"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "passes arguments to subcommand classes" do
|
211
|
+
capture(:stdout){ Scripts::MyDefaults.start(["barn", "open", "shotgun"]) }.strip.should == "That's going to leave a mark."
|
212
|
+
end
|
213
|
+
|
214
|
+
it "ignores unknown options (the subcommand class will handle them)" do
|
215
|
+
capture(:stdout){ Scripts::MyDefaults.start(["barn", "paint", "blue", "--coats", "4"])}.strip.should == "4 coats of blue paint"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#help" do
|
220
|
+
def shell
|
221
|
+
@shell ||= Thor::Base.shell.new
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "on general" do
|
225
|
+
before(:each) do
|
226
|
+
@content = capture(:stdout){ MyScript.help(shell) }
|
227
|
+
end
|
228
|
+
|
229
|
+
it "provides useful help info for the help method itself" do
|
230
|
+
@content.should =~ /help \[TASK\]\s+# Describe available tasks/
|
231
|
+
end
|
232
|
+
|
233
|
+
it "provides useful help info for a method with params" do
|
234
|
+
@content.should =~ /animal TYPE\s+# horse around/
|
235
|
+
end
|
236
|
+
|
237
|
+
it "uses the maximum terminal size to show tasks" do
|
238
|
+
@shell.should_receive(:terminal_width).and_return(80)
|
239
|
+
content = capture(:stdout){ MyScript.help(shell) }
|
240
|
+
content.should =~ /aaa\.\.\.$/
|
241
|
+
end
|
242
|
+
|
243
|
+
it "provides description for tasks from classes in the same namespace" do
|
244
|
+
@content.should =~ /baz\s+# do some bazing/
|
245
|
+
end
|
246
|
+
|
247
|
+
it "shows superclass tasks" do
|
248
|
+
content = capture(:stdout){ MyChildScript.help(shell) }
|
249
|
+
content.should =~ /foo BAR \s+# do some fooing/
|
250
|
+
end
|
251
|
+
|
252
|
+
it "shows class options information" do
|
253
|
+
content = capture(:stdout){ MyChildScript.help(shell) }
|
254
|
+
content.should =~ /Options\:/
|
255
|
+
content.should =~ /\[\-\-param=N\]/
|
256
|
+
end
|
257
|
+
|
258
|
+
it "injects class arguments into default usage" do
|
259
|
+
content = capture(:stdout){ Scripts::MyScript.help(shell) }
|
260
|
+
content.should =~ /zoo ACCESSOR \-\-param\=PARAM/
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "for a specific task" do
|
265
|
+
it "provides full help info when talking about a specific task" do
|
266
|
+
capture(:stdout) { MyScript.task_help(shell, "foo") }.should == <<-END
|
267
|
+
Usage:
|
268
|
+
thor my_script:foo BAR
|
269
|
+
|
270
|
+
Options:
|
271
|
+
[--force] # Force to do some fooing
|
272
|
+
|
273
|
+
do some fooing
|
274
|
+
This is more info!
|
275
|
+
Everyone likes more info!
|
276
|
+
END
|
277
|
+
end
|
278
|
+
|
279
|
+
it "raises an error if the task can't be found" do
|
280
|
+
lambda {
|
281
|
+
MyScript.task_help(shell, "unknown")
|
282
|
+
}.should raise_error(Thor::UndefinedTaskError, 'Could not find task "unknown" in "my_script" namespace.')
|
283
|
+
end
|
284
|
+
|
285
|
+
it "normalizes names before claiming they don't exist" do
|
286
|
+
capture(:stdout) { MyScript.task_help(shell, "name-with-dashes") }.should =~ /thor my_script:name-with-dashes/
|
287
|
+
end
|
288
|
+
|
289
|
+
it "uses the long description if it exists" do
|
290
|
+
capture(:stdout) { MyScript.task_help(shell, "long_description") }.should == <<-HELP
|
291
|
+
Usage:
|
292
|
+
thor my_script:long_description
|
293
|
+
|
294
|
+
Description:
|
295
|
+
This is a really really really long description. Here you go. So very long.
|
296
|
+
|
297
|
+
It even has two paragraphs.
|
298
|
+
HELP
|
299
|
+
end
|
300
|
+
|
301
|
+
it "doesn't assign the long description to the next task without one" do
|
302
|
+
capture(:stdout) do
|
303
|
+
MyScript.task_help(shell, "name_with_dashes")
|
304
|
+
end.should_not =~ /so very long/i
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "instance method" do
|
309
|
+
it "calls the class method" do
|
310
|
+
capture(:stdout){ MyScript.start(["help"]) }.should =~ /Tasks:/
|
311
|
+
end
|
312
|
+
|
313
|
+
it "calls the class method" do
|
314
|
+
capture(:stdout){ MyScript.start(["help", "foo"]) }.should =~ /Usage:/
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "when creating tasks" do
|
320
|
+
it "prints a warning if a public method is created without description or usage" do
|
321
|
+
capture(:stdout) {
|
322
|
+
klass = Class.new(Thor)
|
323
|
+
klass.class_eval "def hello_from_thor; end"
|
324
|
+
}.should =~ /\[WARNING\] Attempted to create task "hello_from_thor" without usage or description/
|
325
|
+
end
|
326
|
+
|
327
|
+
it "does not print if overwriting a previous task" do
|
328
|
+
capture(:stdout) {
|
329
|
+
klass = Class.new(Thor)
|
330
|
+
klass.class_eval "def help; end"
|
331
|
+
}.should be_empty
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "edge-cases" do
|
336
|
+
it "can handle boolean options followed by arguments" do
|
337
|
+
klass = Class.new(Thor) do
|
338
|
+
method_option :loud, :type => :boolean
|
339
|
+
desc "hi NAME", "say hi to name"
|
340
|
+
def hi(name)
|
341
|
+
name.upcase! if options[:loud]
|
342
|
+
"Hi #{name}"
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
klass.start(["hi", "jose"]).should == "Hi jose"
|
347
|
+
klass.start(["hi", "jose", "--loud"]).should == "Hi JOSE"
|
348
|
+
klass.start(["hi", "--loud", "jose"]).should == "Hi JOSE"
|
349
|
+
end
|
350
|
+
|
351
|
+
it "passes through unknown options" do
|
352
|
+
klass = Class.new(Thor) do
|
353
|
+
desc "unknown", "passing unknown options"
|
354
|
+
def unknown(*args)
|
355
|
+
args
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
klass.start(["unknown", "foo", "--bar", "baz", "bat", "--bam"]).should == ["foo", "--bar", "baz", "bat", "--bam"]
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
module Thor::Util
|
4
|
+
def self.clear_user_home!
|
5
|
+
@@user_home = nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Thor::Util do
|
10
|
+
describe "#find_by_namespace" do
|
11
|
+
it "returns 'default' if no namespace is given" do
|
12
|
+
Thor::Util.find_by_namespace('').should == Scripts::MyDefaults
|
13
|
+
end
|
14
|
+
|
15
|
+
it "adds 'default' if namespace starts with :" do
|
16
|
+
Thor::Util.find_by_namespace(':child').should == Scripts::ChildDefault
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the namespace can't be found" do
|
20
|
+
Thor::Util.find_by_namespace('thor:core_ext:ordered_hash').should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a class if it matches the namespace" do
|
24
|
+
Thor::Util.find_by_namespace('app:broken:counter').should == BrokenCounter
|
25
|
+
end
|
26
|
+
|
27
|
+
it "matches classes default namespace" do
|
28
|
+
Thor::Util.find_by_namespace('scripts:my_script').should == Scripts::MyScript
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#namespace_from_thor_class" do
|
33
|
+
it "replaces constant nesting with task namespacing" do
|
34
|
+
Thor::Util.namespace_from_thor_class("Foo::Bar::Baz").should == "foo:bar:baz"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "snake-cases component strings" do
|
38
|
+
Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom").should == "foo_bar:bar_baz:baz_boom"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "accepts class and module objects" do
|
42
|
+
Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash).should == "thor:core_ext:ordered_hash"
|
43
|
+
Thor::Util.namespace_from_thor_class(Thor::Util).should == "thor:util"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "removes Thor::Sandbox namespace" do
|
47
|
+
Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package").should == "package"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#namespaces_in_content" do
|
52
|
+
it "returns an array of names of constants defined in the string" do
|
53
|
+
list = Thor::Util.namespaces_in_content("class Foo; class Bar < Thor; end; end; class Baz; class Bat; end; end")
|
54
|
+
list.should include("foo:bar")
|
55
|
+
list.should_not include("bar:bat")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "doesn't put the newly-defined constants in the enclosing namespace" do
|
59
|
+
Thor::Util.namespaces_in_content("class Blat; end")
|
60
|
+
defined?(Blat).should_not be
|
61
|
+
defined?(Thor::Sandbox::Blat).should be
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#snake_case" do
|
66
|
+
it "preserves no-cap strings" do
|
67
|
+
Thor::Util.snake_case("foo").should == "foo"
|
68
|
+
Thor::Util.snake_case("foo_bar").should == "foo_bar"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "downcases all-caps strings" do
|
72
|
+
Thor::Util.snake_case("FOO").should == "foo"
|
73
|
+
Thor::Util.snake_case("FOO_BAR").should == "foo_bar"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "downcases initial-cap strings" do
|
77
|
+
Thor::Util.snake_case("Foo").should == "foo"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "replaces camel-casing with underscores" do
|
81
|
+
Thor::Util.snake_case("FooBarBaz").should == "foo_bar_baz"
|
82
|
+
Thor::Util.snake_case("Foo_BarBaz").should == "foo_bar_baz"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "places underscores between multiple capitals" do
|
86
|
+
Thor::Util.snake_case("ABClass").should == "a_b_class"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#find_class_and_task_by_namespace" do
|
91
|
+
it "returns a Thor::Group class if full namespace matches" do
|
92
|
+
Thor::Util.find_class_and_task_by_namespace("my_counter").should == [MyCounter, nil]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns a Thor class if full namespace matches" do
|
96
|
+
Thor::Util.find_class_and_task_by_namespace("thor").should == [Thor, nil]
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns a Thor class and the task name" do
|
100
|
+
Thor::Util.find_class_and_task_by_namespace("thor:help").should == [Thor, "help"]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "falls back in the namespace:task look up even if a full namespace does not match" do
|
104
|
+
Thor.const_set(:Help, Module.new)
|
105
|
+
Thor::Util.find_class_and_task_by_namespace("thor:help").should == [Thor, "help"]
|
106
|
+
Thor.send :remove_const, :Help
|
107
|
+
end
|
108
|
+
|
109
|
+
it "falls back on the default namespace class if nothing else matches" do
|
110
|
+
Thor::Util.find_class_and_task_by_namespace("test").should == [Scripts::MyDefaults, "test"]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#thor_classes_in" do
|
115
|
+
it "returns thor classes inside the given class" do
|
116
|
+
Thor::Util.thor_classes_in(MyScript).should == [MyScript::AnotherScript]
|
117
|
+
Thor::Util.thor_classes_in(MyScript::AnotherScript).should be_empty
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#user_home" do
|
122
|
+
before(:each) do
|
123
|
+
ENV.stub!(:[])
|
124
|
+
Thor::Util.clear_user_home!
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns the user path if none variable is set on the environment" do
|
128
|
+
Thor::Util.user_home.should == File.expand_path("~")
|
129
|
+
end
|
130
|
+
|
131
|
+
it "returns the *unix system path if file cannot be expanded and separator does not exist" do
|
132
|
+
File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
|
133
|
+
previous_value = File::ALT_SEPARATOR
|
134
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) }
|
135
|
+
Thor::Util.user_home.should == "/"
|
136
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns the windows system path if file cannot be expanded and a separator exists" do
|
140
|
+
File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
|
141
|
+
previous_value = File::ALT_SEPARATOR
|
142
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) }
|
143
|
+
Thor::Util.user_home.should == "C:/"
|
144
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
|
145
|
+
end
|
146
|
+
|
147
|
+
it "returns HOME/.thor if set" do
|
148
|
+
ENV.stub!(:[]).with("HOME").and_return("/home/user/")
|
149
|
+
Thor::Util.user_home.should == "/home/user/"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns path with HOMEDRIVE and HOMEPATH if set" do
|
153
|
+
ENV.stub!(:[]).with("HOMEDRIVE").and_return("D:/")
|
154
|
+
ENV.stub!(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
|
155
|
+
Thor::Util.user_home.should == "D:/Documents and Settings/James"
|
156
|
+
end
|
157
|
+
|
158
|
+
it "returns APPDATA/.thor if set" do
|
159
|
+
ENV.stub!(:[]).with("APPDATA").and_return("/home/user/")
|
160
|
+
Thor::Util.user_home.should == "/home/user/"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
data/thor.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/thor/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.add_development_dependency "bundler", "~> 1.0"
|
6
|
+
s.add_development_dependency "fakeweb", "~> 1.3"
|
7
|
+
s.add_development_dependency "rake", ">= 0.8"
|
8
|
+
s.add_development_dependency "rdoc", "~> 2.5"
|
9
|
+
s.add_development_dependency "rspec", "~> 2.3"
|
10
|
+
s.add_development_dependency "simplecov", "~> 0.4"
|
11
|
+
s.authors = ['Yehuda Katz', 'José Valim']
|
12
|
+
s.description = %q{A scripting framework that replaces rake, sake and rubigen}
|
13
|
+
s.email = 'ruby-thor@googlegroups.com'
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
15
|
+
s.extra_rdoc_files = ['CHANGELOG.rdoc', 'LICENSE.md', 'README.md', 'Thorfile']
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.homepage = 'http://github.com/wycats/thor'
|
18
|
+
s.name = 'millisami-thor'
|
19
|
+
s.rdoc_options = ['--charset=UTF-8']
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
22
|
+
s.summary = s.description
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.version = Thor::VERSION.dup
|
25
|
+
end
|