thor 0.14.4 → 0.14.5
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/CHANGELOG.rdoc +11 -0
- data/Thorfile +9 -55
- data/lib/thor.rb +17 -0
- data/lib/thor/actions.rb +11 -6
- data/lib/thor/actions/create_file.rb +2 -2
- data/lib/thor/actions/create_link.rb +57 -0
- data/lib/thor/actions/file_manipulation.rb +36 -12
- data/lib/thor/actions/inject_into_file.rb +15 -10
- data/lib/thor/parser/option.rb +1 -1
- data/lib/thor/task.rb +1 -1
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +27 -27
- data/spec/actions/directory_spec.rb +23 -23
- data/spec/actions/empty_directory_spec.rb +12 -12
- data/spec/actions/file_manipulation_spec.rb +65 -42
- data/spec/actions/inject_into_file_spec.rb +24 -24
- data/spec/actions_spec.rb +63 -58
- data/spec/base_spec.rb +60 -60
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +14 -14
- data/spec/core_ext/ordered_hash_spec.rb +28 -28
- data/spec/group_spec.rb +39 -39
- data/spec/invocation_spec.rb +21 -21
- data/spec/parser/argument_spec.rb +7 -7
- data/spec/parser/arguments_spec.rb +11 -11
- data/spec/parser/option_spec.rb +45 -45
- data/spec/parser/options_spec.rb +75 -75
- data/spec/rake_compat_spec.rb +10 -10
- data/spec/register_spec.rb +92 -0
- data/spec/runner_spec.rb +32 -32
- data/spec/shell/basic_spec.rb +18 -18
- data/spec/shell/color_spec.rb +3 -3
- data/spec/shell_spec.rb +10 -10
- data/spec/spec_helper.rb +9 -10
- data/spec/task_spec.rb +8 -8
- data/spec/thor_spec.rb +62 -62
- data/spec/util_spec.rb +35 -35
- metadata +100 -68
- data/spec/spec.opts +0 -1
data/spec/thor_spec.rb
CHANGED
@@ -5,67 +5,67 @@ describe Thor do
|
|
5
5
|
it "sets options to the next method to be invoked" do
|
6
6
|
args = ["foo", "bar", "--force"]
|
7
7
|
arg, options = MyScript.start(args)
|
8
|
-
options.
|
8
|
+
options.should == { "force" => true }
|
9
9
|
end
|
10
10
|
|
11
11
|
describe ":lazy_default" do
|
12
12
|
it "is absent when option is not specified" do
|
13
13
|
arg, options = MyScript.start(["with_optional"])
|
14
|
-
options.
|
14
|
+
options.should == {}
|
15
15
|
end
|
16
16
|
|
17
17
|
it "sets a default that can be overridden for strings" do
|
18
18
|
arg, options = MyScript.start(["with_optional", "--lazy"])
|
19
|
-
options.
|
19
|
+
options.should == { "lazy" => "yes" }
|
20
20
|
|
21
21
|
arg, options = MyScript.start(["with_optional", "--lazy", "yesyes!"])
|
22
|
-
options.
|
22
|
+
options.should == { "lazy" => "yesyes!" }
|
23
23
|
end
|
24
24
|
|
25
25
|
it "sets a default that can be overridden for numerics" do
|
26
26
|
arg, options = MyScript.start(["with_optional", "--lazy-numeric"])
|
27
|
-
options.
|
27
|
+
options.should == { "lazy_numeric" => 42 }
|
28
28
|
|
29
29
|
arg, options = MyScript.start(["with_optional", "--lazy-numeric", 20000])
|
30
|
-
options.
|
30
|
+
options.should == { "lazy_numeric" => 20000 }
|
31
31
|
end
|
32
32
|
|
33
33
|
it "sets a default that can be overridden for arrays" do
|
34
34
|
arg, options = MyScript.start(["with_optional", "--lazy-array"])
|
35
|
-
options.
|
35
|
+
options.should == { "lazy_array" => %w[eat at joes] }
|
36
36
|
|
37
37
|
arg, options = MyScript.start(["with_optional", "--lazy-array", "hello", "there"])
|
38
|
-
options.
|
38
|
+
options.should == { "lazy_array" => %w[hello there] }
|
39
39
|
end
|
40
40
|
|
41
41
|
it "sets a default that can be overridden for hashes" do
|
42
42
|
arg, options = MyScript.start(["with_optional", "--lazy-hash"])
|
43
|
-
options.
|
43
|
+
options.should == { "lazy_hash" => {'swedish' => 'meatballs'} }
|
44
44
|
|
45
45
|
arg, options = MyScript.start(["with_optional", "--lazy-hash", "polish:sausage"])
|
46
|
-
options.
|
46
|
+
options.should == { "lazy_hash" => {'polish' => 'sausage'} }
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
describe "when :for is supplied" do
|
51
51
|
it "updates an already defined task" do
|
52
52
|
args, options = MyChildScript.start(["animal", "horse", "--other=fish"])
|
53
|
-
options[:other].
|
53
|
+
options[:other].should == "fish"
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "and the target is on the parent class" do
|
57
57
|
it "updates an already defined task" do
|
58
58
|
args = ["example_default_task", "my_param", "--new-option=verified"]
|
59
59
|
options = Scripts::MyScript.start(args)
|
60
|
-
options[:new_option].
|
60
|
+
options[:new_option].should == "verified"
|
61
61
|
end
|
62
62
|
|
63
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"].
|
64
|
+
Scripts::MyScript.tasks["example_default_task"].should_not be_nil
|
65
65
|
end
|
66
66
|
|
67
67
|
it "clones the parent task" do
|
68
|
-
Scripts::MyScript.tasks["example_default_task"].
|
68
|
+
Scripts::MyScript.tasks["example_default_task"].should_not == MyChildScript.tasks["example_default_task"]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -73,48 +73,48 @@ describe Thor do
|
|
73
73
|
|
74
74
|
describe "#default_task" do
|
75
75
|
it "sets a default task" do
|
76
|
-
MyScript.default_task.
|
76
|
+
MyScript.default_task.should == "example_default_task"
|
77
77
|
end
|
78
78
|
|
79
79
|
it "invokes the default task if no command is specified" do
|
80
|
-
MyScript.start([]).
|
80
|
+
MyScript.start([]).should == "default task"
|
81
81
|
end
|
82
82
|
|
83
83
|
it "invokes the default task if no command is specified even if switches are given" do
|
84
|
-
MyScript.start(["--with", "option"]).
|
84
|
+
MyScript.start(["--with", "option"]).should == {"with"=>"option"}
|
85
85
|
end
|
86
86
|
|
87
87
|
it "inherits the default task from parent" do
|
88
|
-
MyChildScript.default_task.
|
88
|
+
MyChildScript.default_task.should == "example_default_task"
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
describe "#map" do
|
93
93
|
it "calls the alias of a method if one is provided" do
|
94
|
-
MyScript.start(["-T", "fish"]).
|
94
|
+
MyScript.start(["-T", "fish"]).should == ["fish"]
|
95
95
|
end
|
96
96
|
|
97
97
|
it "calls the alias of a method if several are provided via .map" do
|
98
|
-
MyScript.start(["-f", "fish"]).
|
99
|
-
MyScript.start(["--foo", "fish"]).
|
98
|
+
MyScript.start(["-f", "fish"]).should == ["fish", {}]
|
99
|
+
MyScript.start(["--foo", "fish"]).should == ["fish", {}]
|
100
100
|
end
|
101
101
|
|
102
102
|
it "inherits all mappings from parent" do
|
103
|
-
MyChildScript.default_task.
|
103
|
+
MyChildScript.default_task.should == "example_default_task"
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
describe "#desc" do
|
108
108
|
it "provides description for a task" do
|
109
109
|
content = capture(:stdout) { MyScript.start(["help"]) }
|
110
|
-
content.
|
110
|
+
content.should =~ /thor my_script:zoo\s+# zoo around/m
|
111
111
|
end
|
112
112
|
|
113
113
|
it "provides no namespace if $thor_runner is false" do
|
114
114
|
begin
|
115
115
|
$thor_runner = false
|
116
116
|
content = capture(:stdout) { MyScript.start(["help"]) }
|
117
|
-
content.
|
117
|
+
content.should =~ /thor zoo\s+# zoo around/m
|
118
118
|
ensure
|
119
119
|
$thor_runner = true
|
120
120
|
end
|
@@ -122,17 +122,17 @@ describe Thor do
|
|
122
122
|
|
123
123
|
describe "when :for is supplied" do
|
124
124
|
it "overwrites a previous defined task" do
|
125
|
-
capture(:stdout) { MyChildScript.start(["help"]) }.
|
125
|
+
capture(:stdout) { MyChildScript.start(["help"]) }.should =~ /animal KIND \s+# fish around/m
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
describe "when :hide is supplied" do
|
130
130
|
it "does not show the task in help" do
|
131
|
-
capture(:stdout) { MyScript.start(["help"]) }.
|
131
|
+
capture(:stdout) { MyScript.start(["help"]) }.should_not =~ /this is hidden/m
|
132
132
|
end
|
133
133
|
|
134
134
|
it "but the task is still invokcable not show the task in help" do
|
135
|
-
MyScript.start(["hidden", "yesyes"]).
|
135
|
+
MyScript.start(["hidden", "yesyes"]).should == ["yesyes"]
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -140,79 +140,79 @@ describe Thor do
|
|
140
140
|
describe "#method_options" do
|
141
141
|
it "sets default options if called before an initializer" do
|
142
142
|
options = MyChildScript.class_options
|
143
|
-
options[:force].type.
|
144
|
-
options[:param].type.
|
143
|
+
options[:force].type.should == :boolean
|
144
|
+
options[:param].type.should == :numeric
|
145
145
|
end
|
146
146
|
|
147
147
|
it "overwrites default options if called on the method scope" do
|
148
148
|
args = ["zoo", "--force", "--param", "feathers"]
|
149
149
|
options = MyChildScript.start(args)
|
150
|
-
options.
|
150
|
+
options.should == { "force" => true, "param" => "feathers" }
|
151
151
|
end
|
152
152
|
|
153
153
|
it "allows default options to be merged with method options" do
|
154
154
|
args = ["animal", "bird", "--force", "--param", "1.0", "--other", "tweets"]
|
155
155
|
arg, options = MyChildScript.start(args)
|
156
|
-
arg.
|
157
|
-
options.
|
156
|
+
arg.should == 'bird'
|
157
|
+
options.should == { "force"=>true, "param"=>1.0, "other"=>"tweets" }
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
161
|
describe "#start" do
|
162
162
|
it "calls a no-param method when no params are passed" do
|
163
|
-
MyScript.start(["zoo"]).
|
163
|
+
MyScript.start(["zoo"]).should == true
|
164
164
|
end
|
165
165
|
|
166
166
|
it "calls a single-param method when a single param is passed" do
|
167
|
-
MyScript.start(["animal", "fish"]).
|
167
|
+
MyScript.start(["animal", "fish"]).should == ["fish"]
|
168
168
|
end
|
169
169
|
|
170
170
|
it "does not set options in attributes" do
|
171
|
-
MyScript.start(["with_optional", "--all"]).
|
171
|
+
MyScript.start(["with_optional", "--all"]).should == [nil, { "all" => true }]
|
172
172
|
end
|
173
173
|
|
174
174
|
it "raises an error if a required param is not provided" do
|
175
|
-
capture(:stderr) { MyScript.start(["animal"]) }.strip.
|
175
|
+
capture(:stderr) { MyScript.start(["animal"]) }.strip.should == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".'
|
176
176
|
end
|
177
177
|
|
178
178
|
it "raises an error if the invoked task does not exist" do
|
179
|
-
capture(:stderr) { Amazing.start(["animal"]) }.strip.
|
179
|
+
capture(:stderr) { Amazing.start(["animal"]) }.strip.should == 'Could not find task "animal" in "amazing" namespace.'
|
180
180
|
end
|
181
181
|
|
182
182
|
it "calls method_missing if an unknown method is passed in" do
|
183
|
-
MyScript.start(["unk", "hello"]).
|
183
|
+
MyScript.start(["unk", "hello"]).should == [:unk, ["hello"]]
|
184
184
|
end
|
185
185
|
|
186
186
|
it "does not call a private method no matter what" do
|
187
|
-
capture(:stderr) { MyScript.start(["what"]) }.strip.
|
187
|
+
capture(:stderr) { MyScript.start(["what"]) }.strip.should == 'Could not find task "what" in "my_script" namespace.'
|
188
188
|
end
|
189
189
|
|
190
190
|
it "uses task default options" do
|
191
191
|
options = MyChildScript.start(["animal", "fish"]).last
|
192
|
-
options.
|
192
|
+
options.should == { "other" => "method default" }
|
193
193
|
end
|
194
194
|
|
195
195
|
it "raises when an exception happens within the task call" do
|
196
|
-
lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.
|
196
|
+
lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.should raise_error(ArgumentError)
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
200
|
describe "#subcommand" do
|
201
201
|
it "maps a given subcommand to another Thor subclass" do
|
202
202
|
barn_help = capture(:stdout){ Scripts::MyDefaults.start(["barn"]) }
|
203
|
-
barn_help.
|
203
|
+
barn_help.should include("barn help [COMMAND] # Describe subcommands or one specific subcommand")
|
204
204
|
end
|
205
205
|
|
206
206
|
it "passes commands to subcommand classes" do
|
207
|
-
capture(:stdout){ Scripts::MyDefaults.start(["barn", "open"]) }.strip.
|
207
|
+
capture(:stdout){ Scripts::MyDefaults.start(["barn", "open"]) }.strip.should == "Open sesame!"
|
208
208
|
end
|
209
209
|
|
210
210
|
it "passes arguments to subcommand classes" do
|
211
|
-
capture(:stdout){ Scripts::MyDefaults.start(["barn", "open", "shotgun"]) }.strip.
|
211
|
+
capture(:stdout){ Scripts::MyDefaults.start(["barn", "open", "shotgun"]) }.strip.should == "That's going to leave a mark."
|
212
212
|
end
|
213
213
|
|
214
214
|
it "ignores unknown options (the subcommand class will handle them)" do
|
215
|
-
capture(:stdout){ Scripts::MyDefaults.start(["barn", "paint", "blue", "--coats", "4"])}.strip.
|
215
|
+
capture(:stdout){ Scripts::MyDefaults.start(["barn", "paint", "blue", "--coats", "4"])}.strip.should == "4 coats of blue paint"
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
@@ -227,43 +227,43 @@ describe Thor do
|
|
227
227
|
end
|
228
228
|
|
229
229
|
it "provides useful help info for the help method itself" do
|
230
|
-
@content.
|
230
|
+
@content.should =~ /help \[TASK\]\s+# Describe available tasks/
|
231
231
|
end
|
232
232
|
|
233
233
|
it "provides useful help info for a method with params" do
|
234
|
-
@content.
|
234
|
+
@content.should =~ /animal TYPE\s+# horse around/
|
235
235
|
end
|
236
236
|
|
237
237
|
it "uses the maximum terminal size to show tasks" do
|
238
238
|
@shell.should_receive(:terminal_width).and_return(80)
|
239
239
|
content = capture(:stdout){ MyScript.help(shell) }
|
240
|
-
content.
|
240
|
+
content.should =~ /aaa\.\.\.$/
|
241
241
|
end
|
242
242
|
|
243
243
|
it "provides description for tasks from classes in the same namespace" do
|
244
|
-
@content.
|
244
|
+
@content.should =~ /baz\s+# do some bazing/
|
245
245
|
end
|
246
246
|
|
247
247
|
it "shows superclass tasks" do
|
248
248
|
content = capture(:stdout){ MyChildScript.help(shell) }
|
249
|
-
content.
|
249
|
+
content.should =~ /foo BAR \s+# do some fooing/
|
250
250
|
end
|
251
251
|
|
252
252
|
it "shows class options information" do
|
253
253
|
content = capture(:stdout){ MyChildScript.help(shell) }
|
254
|
-
content.
|
255
|
-
content.
|
254
|
+
content.should =~ /Options\:/
|
255
|
+
content.should =~ /\[\-\-param=N\]/
|
256
256
|
end
|
257
257
|
|
258
258
|
it "injects class arguments into default usage" do
|
259
259
|
content = capture(:stdout){ Scripts::MyScript.help(shell) }
|
260
|
-
content.
|
260
|
+
content.should =~ /zoo ACCESSOR \-\-param\=PARAM/
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
264
|
describe "for a specific task" do
|
265
265
|
it "provides full help info when talking about a specific task" do
|
266
|
-
capture(:stdout) { MyScript.task_help(shell, "foo") }.
|
266
|
+
capture(:stdout) { MyScript.task_help(shell, "foo") }.should == <<-END
|
267
267
|
Usage:
|
268
268
|
thor my_script:foo BAR
|
269
269
|
|
@@ -279,15 +279,15 @@ END
|
|
279
279
|
it "raises an error if the task can't be found" do
|
280
280
|
lambda {
|
281
281
|
MyScript.task_help(shell, "unknown")
|
282
|
-
}.
|
282
|
+
}.should raise_error(Thor::UndefinedTaskError, 'Could not find task "unknown" in "my_script" namespace.')
|
283
283
|
end
|
284
284
|
|
285
285
|
it "normalizes names before claiming they don't exist" do
|
286
|
-
capture(:stdout) { MyScript.task_help(shell, "name-with-dashes") }.
|
286
|
+
capture(:stdout) { MyScript.task_help(shell, "name-with-dashes") }.should =~ /thor my_script:name-with-dashes/
|
287
287
|
end
|
288
288
|
|
289
289
|
it "uses the long description if it exists" do
|
290
|
-
capture(:stdout) { MyScript.task_help(shell, "long_description") }.
|
290
|
+
capture(:stdout) { MyScript.task_help(shell, "long_description") }.should == <<-HELP
|
291
291
|
Usage:
|
292
292
|
thor my_script:long_description
|
293
293
|
|
@@ -301,17 +301,17 @@ HELP
|
|
301
301
|
it "doesn't assign the long description to the next task without one" do
|
302
302
|
capture(:stdout) do
|
303
303
|
MyScript.task_help(shell, "name_with_dashes")
|
304
|
-
end.
|
304
|
+
end.should_not =~ /so very long/i
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
308
308
|
describe "instance method" do
|
309
309
|
it "calls the class method" do
|
310
|
-
capture(:stdout){ MyScript.start(["help"]) }.
|
310
|
+
capture(:stdout){ MyScript.start(["help"]) }.should =~ /Tasks:/
|
311
311
|
end
|
312
312
|
|
313
313
|
it "calls the class method" do
|
314
|
-
capture(:stdout){ MyScript.start(["help", "foo"]) }.
|
314
|
+
capture(:stdout){ MyScript.start(["help", "foo"]) }.should =~ /Usage:/
|
315
315
|
end
|
316
316
|
end
|
317
317
|
end
|
@@ -321,14 +321,14 @@ HELP
|
|
321
321
|
capture(:stdout) {
|
322
322
|
klass = Class.new(Thor)
|
323
323
|
klass.class_eval "def hello_from_thor; end"
|
324
|
-
}.
|
324
|
+
}.should =~ /\[WARNING\] Attempted to create task "hello_from_thor" without usage or description/
|
325
325
|
end
|
326
326
|
|
327
327
|
it "does not print if overwriting a previous task" do
|
328
328
|
capture(:stdout) {
|
329
329
|
klass = Class.new(Thor)
|
330
330
|
klass.class_eval "def help; end"
|
331
|
-
}.
|
331
|
+
}.should be_empty
|
332
332
|
end
|
333
333
|
end
|
334
334
|
end
|
data/spec/util_spec.rb
CHANGED
@@ -9,112 +9,112 @@ end
|
|
9
9
|
describe Thor::Util do
|
10
10
|
describe "#find_by_namespace" do
|
11
11
|
it "returns 'default' if no namespace is given" do
|
12
|
-
Thor::Util.find_by_namespace('').
|
12
|
+
Thor::Util.find_by_namespace('').should == Scripts::MyDefaults
|
13
13
|
end
|
14
14
|
|
15
15
|
it "adds 'default' if namespace starts with :" do
|
16
|
-
Thor::Util.find_by_namespace(':child').
|
16
|
+
Thor::Util.find_by_namespace(':child').should == Scripts::ChildDefault
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns nil if the namespace can't be found" do
|
20
|
-
Thor::Util.find_by_namespace('thor:core_ext:ordered_hash').
|
20
|
+
Thor::Util.find_by_namespace('thor:core_ext:ordered_hash').should be_nil
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns a class if it matches the namespace" do
|
24
|
-
Thor::Util.find_by_namespace('app:broken:counter').
|
24
|
+
Thor::Util.find_by_namespace('app:broken:counter').should == BrokenCounter
|
25
25
|
end
|
26
26
|
|
27
27
|
it "matches classes default namespace" do
|
28
|
-
Thor::Util.find_by_namespace('scripts:my_script').
|
28
|
+
Thor::Util.find_by_namespace('scripts:my_script').should == Scripts::MyScript
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#namespace_from_thor_class" do
|
33
33
|
it "replaces constant nesting with task namespacing" do
|
34
|
-
Thor::Util.namespace_from_thor_class("Foo::Bar::Baz").
|
34
|
+
Thor::Util.namespace_from_thor_class("Foo::Bar::Baz").should == "foo:bar:baz"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "snake-cases component strings" do
|
38
|
-
Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom").
|
38
|
+
Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom").should == "foo_bar:bar_baz:baz_boom"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "accepts class and module objects" do
|
42
|
-
Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash).
|
43
|
-
Thor::Util.namespace_from_thor_class(Thor::Util).
|
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
44
|
end
|
45
45
|
|
46
46
|
it "removes Thor::Sandbox namespace" do
|
47
|
-
Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package").
|
47
|
+
Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package").should == "package"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
describe "#namespaces_in_content" do
|
52
52
|
it "returns an array of names of constants defined in the string" do
|
53
53
|
list = Thor::Util.namespaces_in_content("class Foo; class Bar < Thor; end; end; class Baz; class Bat; end; end")
|
54
|
-
list.
|
55
|
-
list.
|
54
|
+
list.should include("foo:bar")
|
55
|
+
list.should_not include("bar:bat")
|
56
56
|
end
|
57
57
|
|
58
58
|
it "doesn't put the newly-defined constants in the enclosing namespace" do
|
59
59
|
Thor::Util.namespaces_in_content("class Blat; end")
|
60
|
-
defined?(Blat).
|
61
|
-
defined?(Thor::Sandbox::Blat).
|
60
|
+
defined?(Blat).should_not be
|
61
|
+
defined?(Thor::Sandbox::Blat).should be
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe "#snake_case" do
|
66
66
|
it "preserves no-cap strings" do
|
67
|
-
Thor::Util.snake_case("foo").
|
68
|
-
Thor::Util.snake_case("foo_bar").
|
67
|
+
Thor::Util.snake_case("foo").should == "foo"
|
68
|
+
Thor::Util.snake_case("foo_bar").should == "foo_bar"
|
69
69
|
end
|
70
70
|
|
71
71
|
it "downcases all-caps strings" do
|
72
|
-
Thor::Util.snake_case("FOO").
|
73
|
-
Thor::Util.snake_case("FOO_BAR").
|
72
|
+
Thor::Util.snake_case("FOO").should == "foo"
|
73
|
+
Thor::Util.snake_case("FOO_BAR").should == "foo_bar"
|
74
74
|
end
|
75
75
|
|
76
76
|
it "downcases initial-cap strings" do
|
77
|
-
Thor::Util.snake_case("Foo").
|
77
|
+
Thor::Util.snake_case("Foo").should == "foo"
|
78
78
|
end
|
79
79
|
|
80
80
|
it "replaces camel-casing with underscores" do
|
81
|
-
Thor::Util.snake_case("FooBarBaz").
|
82
|
-
Thor::Util.snake_case("Foo_BarBaz").
|
81
|
+
Thor::Util.snake_case("FooBarBaz").should == "foo_bar_baz"
|
82
|
+
Thor::Util.snake_case("Foo_BarBaz").should == "foo_bar_baz"
|
83
83
|
end
|
84
84
|
|
85
85
|
it "places underscores between multiple capitals" do
|
86
|
-
Thor::Util.snake_case("ABClass").
|
86
|
+
Thor::Util.snake_case("ABClass").should == "a_b_class"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe "#find_class_and_task_by_namespace" do
|
91
91
|
it "returns a Thor::Group class if full namespace matches" do
|
92
|
-
Thor::Util.find_class_and_task_by_namespace("my_counter").
|
92
|
+
Thor::Util.find_class_and_task_by_namespace("my_counter").should == [MyCounter, nil]
|
93
93
|
end
|
94
94
|
|
95
95
|
it "returns a Thor class if full namespace matches" do
|
96
|
-
Thor::Util.find_class_and_task_by_namespace("thor").
|
96
|
+
Thor::Util.find_class_and_task_by_namespace("thor").should == [Thor, nil]
|
97
97
|
end
|
98
98
|
|
99
99
|
it "returns a Thor class and the task name" do
|
100
|
-
Thor::Util.find_class_and_task_by_namespace("thor:help").
|
100
|
+
Thor::Util.find_class_and_task_by_namespace("thor:help").should == [Thor, "help"]
|
101
101
|
end
|
102
102
|
|
103
103
|
it "falls back in the namespace:task look up even if a full namespace does not match" do
|
104
104
|
Thor.const_set(:Help, Module.new)
|
105
|
-
Thor::Util.find_class_and_task_by_namespace("thor:help").
|
105
|
+
Thor::Util.find_class_and_task_by_namespace("thor:help").should == [Thor, "help"]
|
106
106
|
Thor.send :remove_const, :Help
|
107
107
|
end
|
108
108
|
|
109
109
|
it "falls back on the default namespace class if nothing else matches" do
|
110
|
-
Thor::Util.find_class_and_task_by_namespace("test").
|
110
|
+
Thor::Util.find_class_and_task_by_namespace("test").should == [Scripts::MyDefaults, "test"]
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
describe "#thor_classes_in" do
|
115
115
|
it "returns thor classes inside the given class" do
|
116
|
-
Thor::Util.thor_classes_in(MyScript).
|
117
|
-
Thor::Util.thor_classes_in(MyScript::AnotherScript).
|
116
|
+
Thor::Util.thor_classes_in(MyScript).should == [MyScript::AnotherScript]
|
117
|
+
Thor::Util.thor_classes_in(MyScript::AnotherScript).should be_empty
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -125,14 +125,14 @@ describe Thor::Util do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it "returns the user path if none variable is set on the environment" do
|
128
|
-
Thor::Util.user_home.
|
128
|
+
Thor::Util.user_home.should == File.expand_path("~")
|
129
129
|
end
|
130
130
|
|
131
131
|
it "returns the *unix system path if file cannot be expanded and separator does not exist" do
|
132
132
|
File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
|
133
133
|
previous_value = File::ALT_SEPARATOR
|
134
134
|
capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) }
|
135
|
-
Thor::Util.user_home.
|
135
|
+
Thor::Util.user_home.should == "/"
|
136
136
|
capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
|
137
137
|
end
|
138
138
|
|
@@ -140,24 +140,24 @@ describe Thor::Util do
|
|
140
140
|
File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
|
141
141
|
previous_value = File::ALT_SEPARATOR
|
142
142
|
capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) }
|
143
|
-
Thor::Util.user_home.
|
143
|
+
Thor::Util.user_home.should == "C:/"
|
144
144
|
capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
|
145
145
|
end
|
146
146
|
|
147
147
|
it "returns HOME/.thor if set" do
|
148
148
|
ENV.stub!(:[]).with("HOME").and_return("/home/user/")
|
149
|
-
Thor::Util.user_home.
|
149
|
+
Thor::Util.user_home.should == "/home/user/"
|
150
150
|
end
|
151
151
|
|
152
152
|
it "returns path with HOMEDRIVE and HOMEPATH if set" do
|
153
153
|
ENV.stub!(:[]).with("HOMEDRIVE").and_return("D:/")
|
154
154
|
ENV.stub!(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
|
155
|
-
Thor::Util.user_home.
|
155
|
+
Thor::Util.user_home.should == "D:/Documents and Settings/James"
|
156
156
|
end
|
157
157
|
|
158
158
|
it "returns APPDATA/.thor if set" do
|
159
159
|
ENV.stub!(:[]).with("APPDATA").and_return("/home/user/")
|
160
|
-
Thor::Util.user_home.
|
160
|
+
Thor::Util.user_home.should == "/home/user/"
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|