thor 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGELOG.rdoc → CHANGELOG.md} +30 -36
- data/README.md +10 -3
- data/lib/thor.rb +205 -180
- data/lib/thor/actions.rb +5 -5
- data/lib/thor/actions/create_link.rb +3 -0
- data/lib/thor/actions/directory.rb +2 -0
- data/lib/thor/actions/file_manipulation.rb +1 -1
- data/lib/thor/base.rb +84 -95
- data/lib/thor/{task.rb → command.rb} +17 -13
- data/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/thor/error.rb +4 -7
- data/lib/thor/group.rb +30 -33
- data/lib/thor/invocation.rb +28 -26
- data/lib/thor/parser/options.rb +3 -1
- data/lib/thor/runner.rb +21 -20
- data/lib/thor/shell/basic.rb +5 -1
- data/lib/thor/shell/color.rb +4 -0
- data/lib/thor/shell/html.rb +4 -0
- data/lib/thor/util.rb +214 -210
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +1 -1
- data/spec/actions/create_link_spec.rb +15 -1
- data/spec/actions/directory_spec.rb +18 -5
- data/spec/actions/empty_directory_spec.rb +1 -1
- data/spec/actions/file_manipulation_spec.rb +13 -13
- data/spec/actions/inject_into_file_spec.rb +1 -1
- data/spec/actions_spec.rb +1 -1
- data/spec/base_spec.rb +40 -24
- data/spec/command_spec.rb +80 -0
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +1 -1
- data/spec/core_ext/ordered_hash_spec.rb +1 -1
- data/spec/exit_condition_spec.rb +3 -3
- data/spec/fixtures/{task.thor → command.thor} +0 -0
- data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/spec/fixtures/doc/COMMENTER +11 -0
- data/spec/fixtures/doc/README +3 -0
- data/spec/fixtures/doc/block_helper.rb +3 -0
- data/spec/fixtures/doc/config.rb +1 -0
- data/spec/fixtures/doc/config.yaml.tt +1 -0
- data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/fixtures/group.thor +24 -10
- data/spec/fixtures/invoke.thor +3 -3
- data/spec/fixtures/script.thor +40 -15
- data/spec/fixtures/subcommand.thor +17 -0
- data/spec/group_spec.rb +13 -13
- data/spec/{spec_helper.rb → helper.rb} +11 -7
- data/spec/invocation_spec.rb +16 -16
- data/spec/parser/argument_spec.rb +4 -4
- data/spec/parser/arguments_spec.rb +1 -1
- data/spec/parser/option_spec.rb +1 -1
- data/spec/parser/options_spec.rb +6 -1
- data/spec/rake_compat_spec.rb +1 -1
- data/spec/register_spec.rb +12 -12
- data/spec/runner_spec.rb +36 -36
- data/spec/shell/basic_spec.rb +9 -10
- data/spec/shell/color_spec.rb +16 -2
- data/spec/shell/html_spec.rb +1 -1
- data/spec/shell_spec.rb +1 -1
- data/spec/subcommand_spec.rb +30 -0
- data/spec/thor_spec.rb +81 -78
- data/spec/util_spec.rb +10 -10
- data/thor.gemspec +22 -18
- metadata +49 -38
- data/.gitignore +0 -44
- data/.rspec +0 -3
- data/.travis.yml +0 -8
- data/Gemfile +0 -19
- data/bin/rake2thor +0 -86
- data/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/spec/task_spec.rb +0 -80
data/spec/thor_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
describe Thor do
|
4
4
|
describe "#method_option" do
|
@@ -48,44 +48,44 @@ describe Thor do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
describe "when :for is supplied" do
|
51
|
-
it "updates an already defined
|
51
|
+
it "updates an already defined command" do
|
52
52
|
args, options = MyChildScript.start(["animal", "horse", "--other=fish"])
|
53
53
|
expect(options[:other]).to eq("fish")
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "and the target is on the parent class" do
|
57
|
-
it "updates an already defined
|
58
|
-
args = ["
|
57
|
+
it "updates an already defined command" do
|
58
|
+
args = ["example_default_command", "my_param", "--new-option=verified"]
|
59
59
|
options = Scripts::MyScript.start(args)
|
60
60
|
expect(options[:new_option]).to eq("verified")
|
61
61
|
end
|
62
62
|
|
63
|
-
it "adds a
|
64
|
-
expect(Scripts::MyScript.
|
63
|
+
it "adds a command to the command list if the updated command is on the parent class" do
|
64
|
+
expect(Scripts::MyScript.commands["example_default_command"]).to be
|
65
65
|
end
|
66
66
|
|
67
|
-
it "clones the parent
|
68
|
-
expect(Scripts::MyScript.
|
67
|
+
it "clones the parent command" do
|
68
|
+
expect(Scripts::MyScript.commands["example_default_command"]).not_to eq(MyChildScript.commands["example_default_command"])
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
describe "#
|
75
|
-
it "sets a default
|
76
|
-
expect(MyScript.
|
74
|
+
describe "#default_command" do
|
75
|
+
it "sets a default command" do
|
76
|
+
expect(MyScript.default_command).to eq("example_default_command")
|
77
77
|
end
|
78
78
|
|
79
|
-
it "invokes the default
|
80
|
-
expect(MyScript.start([])).to eq("default
|
79
|
+
it "invokes the default command if no command is specified" do
|
80
|
+
expect(MyScript.start([])).to eq("default command")
|
81
81
|
end
|
82
82
|
|
83
|
-
it "invokes the default
|
83
|
+
it "invokes the default command if no command is specified even if switches are given" do
|
84
84
|
expect(MyScript.start(["--with", "option"])).to eq({"with"=>"option"})
|
85
85
|
end
|
86
86
|
|
87
|
-
it "inherits the default
|
88
|
-
expect(MyChildScript.
|
87
|
+
it "inherits the default command from parent" do
|
88
|
+
expect(MyChildScript.default_command).to eq("example_default_command")
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -101,17 +101,17 @@ describe Thor do
|
|
101
101
|
return options, args
|
102
102
|
end
|
103
103
|
|
104
|
-
desc "boring", "An ordinary
|
104
|
+
desc "boring", "An ordinary command"
|
105
105
|
def boring(*args)
|
106
106
|
return options, args
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
it "passes remaining args to
|
110
|
+
it "passes remaining args to command when it encounters a non-option" do
|
111
111
|
expect(my_script.start(%w[exec command --verbose])).to eq [{}, ["command", "--verbose"]]
|
112
112
|
end
|
113
113
|
|
114
|
-
it "passes remaining args to
|
114
|
+
it "passes remaining args to command when it encounters an unknown option" do
|
115
115
|
expect(my_script.start(%w[exec --foo command --bar])).to eq [{}, ["--foo", "command", "--bar"]]
|
116
116
|
end
|
117
117
|
|
@@ -123,19 +123,19 @@ describe Thor do
|
|
123
123
|
expect(my_script.start(%w[exec --mode rashly command])).to eq [{"mode" => "rashly"}, ["command"]]
|
124
124
|
end
|
125
125
|
|
126
|
-
it "still passes everything after -- to
|
126
|
+
it "still passes everything after -- to command" do
|
127
127
|
expect(my_script.start(%w[exec -- --verbose])).to eq [{}, ["--verbose"]]
|
128
128
|
end
|
129
129
|
|
130
|
-
it "does not affect ordinary
|
130
|
+
it "does not affect ordinary commands" do
|
131
131
|
expect(my_script.start(%w[boring command --verbose])).to eq [{"verbose" => true}, ["command"]]
|
132
132
|
end
|
133
133
|
|
134
|
-
context "when provided with multiple
|
134
|
+
context "when provided with multiple command names" do
|
135
135
|
klass = Class.new(Thor) do
|
136
136
|
stop_on_unknown_option! :foo, :bar
|
137
137
|
end
|
138
|
-
it "affects all specified
|
138
|
+
it "affects all specified commands" do
|
139
139
|
expect(klass.stop_on_unknown_option?(mock :name => "foo")).to be_true
|
140
140
|
expect(klass.stop_on_unknown_option?(mock :name => "bar")).to be_true
|
141
141
|
expect(klass.stop_on_unknown_option?(mock :name => "baz")).to be_false
|
@@ -147,7 +147,7 @@ describe Thor do
|
|
147
147
|
stop_on_unknown_option! :foo
|
148
148
|
stop_on_unknown_option! :bar
|
149
149
|
end
|
150
|
-
it "affects all specified
|
150
|
+
it "affects all specified commands" do
|
151
151
|
expect(klass.stop_on_unknown_option?(mock :name => "foo")).to be_true
|
152
152
|
expect(klass.stop_on_unknown_option?(mock :name => "bar")).to be_true
|
153
153
|
expect(klass.stop_on_unknown_option?(mock :name => "baz")).to be_false
|
@@ -166,12 +166,25 @@ describe Thor do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it "inherits all mappings from parent" do
|
169
|
-
expect(MyChildScript.
|
169
|
+
expect(MyChildScript.default_command).to eq("example_default_command")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "#package_name" do
|
174
|
+
it "provides a proper description for a command when the package_name is assigned" do
|
175
|
+
content = capture(:stdout) { PackageNameScript.start(["help"]) }
|
176
|
+
expect(content).to match(/Baboon commands:/m)
|
177
|
+
end
|
178
|
+
|
179
|
+
# TODO: remove this, might be redundant, just wanted to prove full coverage
|
180
|
+
it "provides a proper description for a command when the package_name is NOT assigned" do
|
181
|
+
content = capture(:stdout) { MyScript.start(["help"]) }
|
182
|
+
expect(content).to match(/Commands:/m)
|
170
183
|
end
|
171
184
|
end
|
172
185
|
|
173
186
|
describe "#desc" do
|
174
|
-
it "provides description for a
|
187
|
+
it "provides description for a command" do
|
175
188
|
content = capture(:stdout) { MyScript.start(["help"]) }
|
176
189
|
expect(content).to match(/thor my_script:zoo\s+# zoo around/m)
|
177
190
|
end
|
@@ -187,17 +200,17 @@ describe Thor do
|
|
187
200
|
end
|
188
201
|
|
189
202
|
describe "when :for is supplied" do
|
190
|
-
it "overwrites a previous defined
|
203
|
+
it "overwrites a previous defined command" do
|
191
204
|
expect(capture(:stdout) { MyChildScript.start(["help"]) }).to match(/animal KIND \s+# fish around/m)
|
192
205
|
end
|
193
206
|
end
|
194
207
|
|
195
208
|
describe "when :hide is supplied" do
|
196
|
-
it "does not show the
|
209
|
+
it "does not show the command in help" do
|
197
210
|
expect(capture(:stdout) { MyScript.start(["help"]) }).not_to match(/this is hidden/m)
|
198
211
|
end
|
199
212
|
|
200
|
-
it "but the
|
213
|
+
it "but the command is still invokcable not show the command in help" do
|
201
214
|
expect(MyScript.start(["hidden", "yesyes"])).to eq(["yesyes"])
|
202
215
|
end
|
203
216
|
end
|
@@ -237,12 +250,21 @@ describe Thor do
|
|
237
250
|
expect(MyScript.start(["with_optional", "--all"])).to eq([nil, { "all" => true }, []])
|
238
251
|
end
|
239
252
|
|
240
|
-
it "raises an error if
|
241
|
-
|
253
|
+
it "raises an error if the wrong number of params are provided" do
|
254
|
+
arity_asserter = lambda do |args, msg|
|
255
|
+
stderr = capture(:stderr) { Scripts::Arities.start(args) }
|
256
|
+
expect(stderr.strip).to eq(msg)
|
257
|
+
end
|
258
|
+
arity_asserter.call ["zero_args", "one" ], %Q'ERROR: thor zero_args was called with arguments ["one"]\nUsage: "thor scripts:arities:zero_args".'
|
259
|
+
arity_asserter.call ["one_arg" ], %Q'ERROR: thor one_arg was called with no arguments\nUsage: "thor scripts:arities:one_arg ARG".'
|
260
|
+
arity_asserter.call ["one_arg", "one", "two" ], %Q'ERROR: thor one_arg was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:one_arg ARG".'
|
261
|
+
arity_asserter.call ["one_arg", "one", "two" ], %Q'ERROR: thor one_arg was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:one_arg ARG".'
|
262
|
+
arity_asserter.call ["two_args", "one" ], %Q'ERROR: thor two_args was called with arguments ["one"]\nUsage: "thor scripts:arities:two_args ARG1 ARG2".'
|
263
|
+
arity_asserter.call ["optional_arg", "one", "two" ], %Q'ERROR: thor optional_arg was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:optional_arg [ARG]".'
|
242
264
|
end
|
243
265
|
|
244
|
-
it "raises an error if the invoked
|
245
|
-
expect(capture(:stderr) { Amazing.start(["animal"]) }.strip).to eq('Could not find
|
266
|
+
it "raises an error if the invoked command does not exist" do
|
267
|
+
expect(capture(:stderr) { Amazing.start(["animal"]) }.strip).to eq('Could not find command "animal" in "amazing" namespace.')
|
246
268
|
end
|
247
269
|
|
248
270
|
it "calls method_missing if an unknown method is passed in" do
|
@@ -250,15 +272,15 @@ describe Thor do
|
|
250
272
|
end
|
251
273
|
|
252
274
|
it "does not call a private method no matter what" do
|
253
|
-
expect(capture(:stderr) { MyScript.start(["what"]) }.strip).to eq('Could not find
|
275
|
+
expect(capture(:stderr) { MyScript.start(["what"]) }.strip).to eq('Could not find command "what" in "my_script" namespace.')
|
254
276
|
end
|
255
277
|
|
256
|
-
it "uses
|
278
|
+
it "uses command default options" do
|
257
279
|
options = MyChildScript.start(["animal", "fish"]).last
|
258
280
|
expect(options).to eq({ "other" => "method default" })
|
259
281
|
end
|
260
282
|
|
261
|
-
it "raises when an exception happens within the
|
283
|
+
it "raises when an exception happens within the command call" do
|
262
284
|
expect{ MyScript.start(["call_myself_with_wrong_arity"]) }.to raise_error(ArgumentError)
|
263
285
|
end
|
264
286
|
|
@@ -267,8 +289,8 @@ describe Thor do
|
|
267
289
|
expect(MyScript.start(["z"])).to eq(MyScript.start(["zoo"]))
|
268
290
|
end
|
269
291
|
|
270
|
-
it "invokes a command, even when there's an alias
|
271
|
-
expect(MyScript.start(["hi"])).to eq(MyScript.start(["hidden"]))
|
292
|
+
it "invokes a command, even when there's an alias it resolves to the same command" do
|
293
|
+
expect(MyScript.start(["hi", "arg"])).to eq(MyScript.start(["hidden", "arg"]))
|
272
294
|
end
|
273
295
|
|
274
296
|
it "invokes an alias" do
|
@@ -278,35 +300,16 @@ describe Thor do
|
|
278
300
|
|
279
301
|
context "when the user enters an ambiguous substring of a command" do
|
280
302
|
it "raises an exception that explains the ambiguity" do
|
281
|
-
expect{ MyScript.start(["call"]) }.to raise_error(ArgumentError, 'Ambiguous
|
303
|
+
expect{ MyScript.start(["call"]) }.to raise_error(ArgumentError, 'Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]')
|
282
304
|
end
|
283
305
|
|
284
306
|
it "raises an exception when there is an alias" do
|
285
|
-
expect{ MyScript.start(["f"]) }.to raise_error(ArgumentError, 'Ambiguous
|
307
|
+
expect{ MyScript.start(["f"]) }.to raise_error(ArgumentError, 'Ambiguous command f matches [foo, fu]')
|
286
308
|
end
|
287
309
|
end
|
288
310
|
|
289
311
|
end
|
290
312
|
|
291
|
-
describe "#subcommand" do
|
292
|
-
it "maps a given subcommand to another Thor subclass" do
|
293
|
-
barn_help = capture(:stdout) { Scripts::MyDefaults.start(["barn"]) }
|
294
|
-
expect(barn_help).to include("barn help [COMMAND] # Describe subcommands or one specific subcommand")
|
295
|
-
end
|
296
|
-
|
297
|
-
it "passes commands to subcommand classes" do
|
298
|
-
expect(capture(:stdout) { Scripts::MyDefaults.start(["barn", "open"]) }.strip).to eq("Open sesame!")
|
299
|
-
end
|
300
|
-
|
301
|
-
it "passes arguments to subcommand classes" do
|
302
|
-
expect(capture(:stdout) { Scripts::MyDefaults.start(["barn", "open", "shotgun"]) }.strip).to eq("That's going to leave a mark.")
|
303
|
-
end
|
304
|
-
|
305
|
-
it "ignores unknown options (the subcommand class will handle them)" do
|
306
|
-
expect(capture(:stdout) { Scripts::MyDefaults.start(["barn", "paint", "blue", "--coats", "4"])}.strip).to eq("4 coats of blue paint")
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
313
|
describe "#help" do
|
311
314
|
def shell
|
312
315
|
@shell ||= Thor::Base.shell.new
|
@@ -318,24 +321,24 @@ describe Thor do
|
|
318
321
|
end
|
319
322
|
|
320
323
|
it "provides useful help info for the help method itself" do
|
321
|
-
expect(@content).to match(/help \[
|
324
|
+
expect(@content).to match(/help \[COMMAND\]\s+# Describe available commands/)
|
322
325
|
end
|
323
326
|
|
324
327
|
it "provides useful help info for a method with params" do
|
325
328
|
expect(@content).to match(/animal TYPE\s+# horse around/)
|
326
329
|
end
|
327
330
|
|
328
|
-
it "uses the maximum terminal size to show
|
331
|
+
it "uses the maximum terminal size to show commands" do
|
329
332
|
@shell.should_receive(:terminal_width).and_return(80)
|
330
333
|
content = capture(:stdout) { MyScript.help(shell) }
|
331
334
|
expect(content).to match(/aaa\.\.\.$/)
|
332
335
|
end
|
333
336
|
|
334
|
-
it "provides description for
|
337
|
+
it "provides description for commands from classes in the same namespace" do
|
335
338
|
expect(@content).to match(/baz\s+# do some bazing/)
|
336
339
|
end
|
337
340
|
|
338
|
-
it "shows superclass
|
341
|
+
it "shows superclass commands" do
|
339
342
|
content = capture(:stdout) { MyChildScript.help(shell) }
|
340
343
|
expect(content).to match(/foo BAR \s+# do some fooing/)
|
341
344
|
end
|
@@ -352,9 +355,9 @@ describe Thor do
|
|
352
355
|
end
|
353
356
|
end
|
354
357
|
|
355
|
-
describe "for a specific
|
356
|
-
it "provides full help info when talking about a specific
|
357
|
-
expect(capture(:stdout) { MyScript.
|
358
|
+
describe "for a specific command" do
|
359
|
+
it "provides full help info when talking about a specific command" do
|
360
|
+
expect(capture(:stdout) { MyScript.command_help(shell, "foo") }).to eq(<<-END)
|
358
361
|
Usage:
|
359
362
|
thor my_script:foo BAR
|
360
363
|
|
@@ -367,18 +370,18 @@ do some fooing
|
|
367
370
|
END
|
368
371
|
end
|
369
372
|
|
370
|
-
it "raises an error if the
|
373
|
+
it "raises an error if the command can't be found" do
|
371
374
|
expect {
|
372
|
-
MyScript.
|
373
|
-
}.to raise_error(Thor::
|
375
|
+
MyScript.command_help(shell, "unknown")
|
376
|
+
}.to raise_error(Thor::UndefinedCommandError, 'Could not find command "unknown" in "my_script" namespace.')
|
374
377
|
end
|
375
378
|
|
376
379
|
it "normalizes names before claiming they don't exist" do
|
377
|
-
expect(capture(:stdout) { MyScript.
|
380
|
+
expect(capture(:stdout) { MyScript.command_help(shell, "name-with-dashes") }).to match(/thor my_script:name-with-dashes/)
|
378
381
|
end
|
379
382
|
|
380
383
|
it "uses the long description if it exists" do
|
381
|
-
expect(capture(:stdout) { MyScript.
|
384
|
+
expect(capture(:stdout) { MyScript.command_help(shell, "long_description") }).to eq(<<-HELP)
|
382
385
|
Usage:
|
383
386
|
thor my_script:long_description
|
384
387
|
|
@@ -389,16 +392,16 @@ Description:
|
|
389
392
|
HELP
|
390
393
|
end
|
391
394
|
|
392
|
-
it "doesn't assign the long description to the next
|
395
|
+
it "doesn't assign the long description to the next command without one" do
|
393
396
|
expect(capture(:stdout) {
|
394
|
-
MyScript.
|
397
|
+
MyScript.command_help(shell, "name_with_dashes")
|
395
398
|
}).not_to match(/so very long/i)
|
396
399
|
end
|
397
400
|
end
|
398
401
|
|
399
402
|
describe "instance method" do
|
400
403
|
it "calls the class method" do
|
401
|
-
expect(capture(:stdout) { MyScript.start(["help"]) }).to match(/
|
404
|
+
expect(capture(:stdout) { MyScript.start(["help"]) }).to match(/Commands:/)
|
402
405
|
end
|
403
406
|
|
404
407
|
it "calls the class method" do
|
@@ -407,15 +410,15 @@ HELP
|
|
407
410
|
end
|
408
411
|
end
|
409
412
|
|
410
|
-
describe "when creating
|
413
|
+
describe "when creating commands" do
|
411
414
|
it "prints a warning if a public method is created without description or usage" do
|
412
415
|
expect(capture(:stdout) {
|
413
416
|
klass = Class.new(Thor)
|
414
417
|
klass.class_eval "def hello_from_thor; end"
|
415
|
-
}).to match(/\[WARNING\] Attempted to create
|
418
|
+
}).to match(/\[WARNING\] Attempted to create command "hello_from_thor" without usage or description/)
|
416
419
|
end
|
417
420
|
|
418
|
-
it "does not print if overwriting a previous
|
421
|
+
it "does not print if overwriting a previous command" do
|
419
422
|
expect(capture(:stdout) {
|
420
423
|
klass = Class.new(Thor)
|
421
424
|
klass.class_eval "def help; end"
|
@@ -481,7 +484,7 @@ HELP
|
|
481
484
|
expect(klass.start(["unknown", "foo", "--bar", "baz"])).to eq(["foo"])
|
482
485
|
end
|
483
486
|
|
484
|
-
it "send as a
|
487
|
+
it "send as a command name" do
|
485
488
|
expect(MyScript.start(["send"])).to eq(true)
|
486
489
|
end
|
487
490
|
end
|
data/spec/util_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
module Thor::Util
|
4
4
|
def self.clear_user_home!
|
@@ -30,7 +30,7 @@ describe Thor::Util do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#namespace_from_thor_class" do
|
33
|
-
it "replaces constant nesting with
|
33
|
+
it "replaces constant nesting with command namespacing" do
|
34
34
|
expect(Thor::Util.namespace_from_thor_class("Foo::Bar::Baz")).to eq("foo:bar:baz")
|
35
35
|
end
|
36
36
|
|
@@ -87,27 +87,27 @@ describe Thor::Util do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
describe "#
|
90
|
+
describe "#find_class_and_command_by_namespace" do
|
91
91
|
it "returns a Thor::Group class if full namespace matches" do
|
92
|
-
expect(Thor::Util.
|
92
|
+
expect(Thor::Util.find_class_and_command_by_namespace("my_counter")).to eq([MyCounter, nil])
|
93
93
|
end
|
94
94
|
|
95
95
|
it "returns a Thor class if full namespace matches" do
|
96
|
-
expect(Thor::Util.
|
96
|
+
expect(Thor::Util.find_class_and_command_by_namespace("thor")).to eq([Thor, nil])
|
97
97
|
end
|
98
98
|
|
99
|
-
it "returns a Thor class and the
|
100
|
-
expect(Thor::Util.
|
99
|
+
it "returns a Thor class and the command name" do
|
100
|
+
expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
|
101
101
|
end
|
102
102
|
|
103
|
-
it "falls back in the namespace:
|
103
|
+
it "falls back in the namespace:command look up even if a full namespace does not match" do
|
104
104
|
Thor.const_set(:Help, Module.new)
|
105
|
-
expect(Thor::Util.
|
105
|
+
expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([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
|
-
expect(Thor::Util.
|
110
|
+
expect(Thor::Util.find_class_and_command_by_namespace("test")).to eq([Scripts::MyDefaults, "test"])
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
data/thor.gemspec
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
require 'thor/version'
|
3
5
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
8
|
+
spec.authors = ['Yehuda Katz', 'José Valim']
|
9
|
+
spec.description = %q{A scripting framework that replaces rake, sake and rubigen}
|
10
|
+
spec.email = 'ruby-thor@googlegroups.com'
|
11
|
+
spec.executables = %w(thor)
|
12
|
+
spec.files = %w(.document CHANGELOG.md LICENSE.md README.md Thorfile thor.gemspec)
|
13
|
+
spec.files += Dir.glob("bin/**/*")
|
14
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
15
|
+
spec.files += Dir.glob("spec/**/*")
|
16
|
+
spec.homepage = 'http://whatisthor.com/'
|
17
|
+
spec.licenses = ['MIT']
|
18
|
+
spec.name = 'thor'
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
spec.required_rubygems_version = '>= 1.3.6'
|
21
|
+
spec.summary = spec.description
|
22
|
+
spec.test_files = Dir.glob("spec/**/*")
|
23
|
+
spec.version = Thor::VERSION
|
20
24
|
end
|