thor 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +13 -7
- data/Thorfile +4 -5
- data/bin/thor +1 -1
- data/lib/thor.rb +78 -67
- data/lib/thor/actions.rb +57 -56
- data/lib/thor/actions/create_file.rb +33 -35
- data/lib/thor/actions/create_link.rb +2 -3
- data/lib/thor/actions/directory.rb +37 -38
- data/lib/thor/actions/empty_directory.rb +67 -69
- data/lib/thor/actions/file_manipulation.rb +17 -15
- data/lib/thor/actions/inject_into_file.rb +27 -29
- data/lib/thor/base.rb +193 -189
- data/lib/thor/command.rb +20 -23
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +21 -24
- data/lib/thor/core_ext/io_binary_read.rb +2 -4
- data/lib/thor/core_ext/ordered_hash.rb +9 -11
- data/lib/thor/error.rb +5 -1
- data/lib/thor/group.rb +53 -54
- data/lib/thor/invocation.rb +44 -38
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/line_editor/basic.rb +35 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/parser/argument.rb +28 -29
- data/lib/thor/parser/arguments.rb +102 -98
- data/lib/thor/parser/option.rb +26 -22
- data/lib/thor/parser/options.rb +86 -86
- data/lib/thor/rake_compat.rb +9 -10
- data/lib/thor/runner.rb +141 -141
- data/lib/thor/shell.rb +27 -34
- data/lib/thor/shell/basic.rb +91 -63
- data/lib/thor/shell/color.rb +44 -43
- data/lib/thor/shell/html.rb +59 -60
- data/lib/thor/util.rb +24 -27
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +25 -27
- data/spec/actions/create_link_spec.rb +19 -18
- data/spec/actions/directory_spec.rb +31 -31
- data/spec/actions/empty_directory_spec.rb +18 -18
- data/spec/actions/file_manipulation_spec.rb +38 -28
- data/spec/actions/inject_into_file_spec.rb +13 -13
- data/spec/actions_spec.rb +43 -43
- data/spec/base_spec.rb +45 -38
- data/spec/command_spec.rb +13 -14
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -19
- data/spec/core_ext/ordered_hash_spec.rb +6 -6
- data/spec/exit_condition_spec.rb +4 -4
- data/spec/fixtures/invoke.thor +19 -0
- data/spec/fixtures/script.thor +1 -1
- data/spec/group_spec.rb +30 -24
- data/spec/helper.rb +28 -15
- data/spec/invocation_spec.rb +39 -19
- data/spec/line_editor/basic_spec.rb +28 -0
- data/spec/line_editor/readline_spec.rb +69 -0
- data/spec/line_editor_spec.rb +43 -0
- data/spec/parser/argument_spec.rb +12 -12
- data/spec/parser/arguments_spec.rb +11 -11
- data/spec/parser/option_spec.rb +33 -25
- data/spec/parser/options_spec.rb +66 -52
- data/spec/quality_spec.rb +75 -0
- data/spec/rake_compat_spec.rb +10 -10
- data/spec/register_spec.rb +60 -30
- data/spec/runner_spec.rb +67 -62
- data/spec/sandbox/application.rb +2 -0
- data/spec/sandbox/app{1}/README +3 -0
- data/spec/sandbox/bundle/execute.rb +6 -0
- data/spec/sandbox/bundle/main.thor +1 -0
- data/spec/sandbox/command.thor +10 -0
- data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
- data/spec/sandbox/doc/COMMENTER +11 -0
- data/spec/sandbox/doc/README +3 -0
- data/spec/sandbox/doc/block_helper.rb +3 -0
- data/spec/sandbox/doc/config.rb +1 -0
- data/spec/sandbox/doc/config.yaml.tt +1 -0
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/sandbox/enum.thor +10 -0
- data/spec/sandbox/group.thor +128 -0
- data/spec/sandbox/invoke.thor +131 -0
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +3 -0
- data/spec/sandbox/script.thor +220 -0
- data/spec/sandbox/subcommand.thor +17 -0
- data/spec/shell/basic_spec.rb +107 -86
- data/spec/shell/color_spec.rb +32 -8
- data/spec/shell/html_spec.rb +3 -4
- data/spec/shell_spec.rb +7 -7
- data/spec/subcommand_spec.rb +20 -2
- data/spec/thor_spec.rb +111 -97
- data/spec/util_spec.rb +30 -30
- data/thor.gemspec +14 -14
- metadata +69 -25
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "helper"
|
2
|
+
require "thor/actions"
|
3
3
|
|
4
4
|
describe Thor::Actions::InjectIntoFile do
|
5
5
|
before do
|
@@ -7,12 +7,12 @@ describe Thor::Actions::InjectIntoFile do
|
|
7
7
|
::FileUtils.cp_r(source_root, destination_root)
|
8
8
|
end
|
9
9
|
|
10
|
-
def invoker(options={})
|
11
|
-
@invoker ||= MyCounter.new([1,2], options,
|
10
|
+
def invoker(options = {})
|
11
|
+
@invoker ||= MyCounter.new([1, 2], options, :destination_root => destination_root)
|
12
12
|
end
|
13
13
|
|
14
14
|
def revoker
|
15
|
-
@revoker ||= MyCounter.new([1,2], {},
|
15
|
+
@revoker ||= MyCounter.new([1, 2], {}, :destination_root => destination_root, :behavior => :revoke)
|
16
16
|
end
|
17
17
|
|
18
18
|
def invoke!(*args, &block)
|
@@ -56,7 +56,7 @@ describe Thor::Actions::InjectIntoFile do
|
|
56
56
|
expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
|
57
57
|
end
|
58
58
|
|
59
|
-
it "does not change the file if already
|
59
|
+
it "does not change the file if already includes content" do
|
60
60
|
invoke! "doc/README", :before => "__end__" do
|
61
61
|
"more content\n"
|
62
62
|
end
|
@@ -70,7 +70,7 @@ describe Thor::Actions::InjectIntoFile do
|
|
70
70
|
expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
|
71
71
|
end
|
72
72
|
|
73
|
-
it "does change the file if already
|
73
|
+
it "does change the file if already includes content and :force is true" do
|
74
74
|
invoke! "doc/README", :before => "__end__" do
|
75
75
|
"more content\n"
|
76
76
|
end
|
@@ -87,40 +87,40 @@ describe Thor::Actions::InjectIntoFile do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
describe "#revoke!" do
|
90
|
-
it "
|
90
|
+
it "subtracts the destination file after injection" do
|
91
91
|
invoke! "doc/README", "\nmore content", :after => "__start__"
|
92
92
|
revoke! "doc/README", "\nmore content", :after => "__start__"
|
93
93
|
expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
|
94
94
|
end
|
95
95
|
|
96
|
-
it "
|
96
|
+
it "subtracts the destination file before injection" do
|
97
97
|
invoke! "doc/README", "more content\n", :before => "__start__"
|
98
98
|
revoke! "doc/README", "more content\n", :before => "__start__"
|
99
99
|
expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
|
100
100
|
end
|
101
101
|
|
102
|
-
it "
|
102
|
+
it "subtracts even with double after injection" do
|
103
103
|
invoke! "doc/README", "\nmore content", :after => "__start__"
|
104
104
|
invoke! "doc/README", "\nanother stuff", :after => "__start__"
|
105
105
|
revoke! "doc/README", "\nmore content", :after => "__start__"
|
106
106
|
expect(File.read(file)).to eq("__start__\nanother stuff\nREADME\n__end__\n")
|
107
107
|
end
|
108
108
|
|
109
|
-
it "
|
109
|
+
it "subtracts even with double before injection" do
|
110
110
|
invoke! "doc/README", "more content\n", :before => "__start__"
|
111
111
|
invoke! "doc/README", "another stuff\n", :before => "__start__"
|
112
112
|
revoke! "doc/README", "more content\n", :before => "__start__"
|
113
113
|
expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n")
|
114
114
|
end
|
115
115
|
|
116
|
-
it "
|
116
|
+
it "subtracts when prepending" do
|
117
117
|
invoke! "doc/README", "more content\n", :after => /\A/
|
118
118
|
invoke! "doc/README", "another stuff\n", :after => /\A/
|
119
119
|
revoke! "doc/README", "more content\n", :after => /\A/
|
120
120
|
expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n")
|
121
121
|
end
|
122
122
|
|
123
|
-
it "
|
123
|
+
it "subtracts when appending" do
|
124
124
|
invoke! "doc/README", "more content\n", :before => /\z/
|
125
125
|
invoke! "doc/README", "another stuff\n", :before => /\z/
|
126
126
|
revoke! "doc/README", "more content\n", :before => /\z/
|
data/spec/actions_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
describe Thor::Actions do
|
4
|
-
def runner(options={})
|
5
|
-
@runner ||= MyCounter.new([1], options,
|
4
|
+
def runner(options = {})
|
5
|
+
@runner ||= MyCounter.new([1], options, :destination_root => destination_root)
|
6
6
|
end
|
7
7
|
|
8
8
|
def action(*args, &block)
|
@@ -32,17 +32,17 @@ describe Thor::Actions do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "when behavior is set to force, overwrite options" do
|
35
|
-
runner = MyCounter.new([1], {
|
35
|
+
runner = MyCounter.new([1], {:force => false, :skip => true}, :behavior => :force)
|
36
36
|
expect(runner.behavior).to eq(:invoke)
|
37
|
-
expect(runner.options.force).to
|
38
|
-
expect(runner.options.skip).not_to
|
37
|
+
expect(runner.options.force).to be true
|
38
|
+
expect(runner.options.skip).not_to be true
|
39
39
|
end
|
40
40
|
|
41
41
|
it "when behavior is set to skip, overwrite options" do
|
42
|
-
runner = MyCounter.new([1], [
|
42
|
+
runner = MyCounter.new([1], %w[--force], :behavior => :skip)
|
43
43
|
expect(runner.behavior).to eq(:invoke)
|
44
|
-
expect(runner.options.force).not_to
|
45
|
-
expect(runner.options.skip).to
|
44
|
+
expect(runner.options.force).not_to be true
|
45
|
+
expect(runner.options.skip).to be true
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -83,11 +83,11 @@ describe Thor::Actions do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "creates proper relative paths for absolute file location" do
|
86
|
-
expect(runner.relative_to_original_destination_root(
|
86
|
+
expect(runner.relative_to_original_destination_root("/test/file")).to eq("/test/file")
|
87
87
|
end
|
88
88
|
|
89
|
-
it "does not fail with files
|
90
|
-
runner = MyCounter.new([1], {},
|
89
|
+
it "does not fail with files containing regexp characters" do
|
90
|
+
runner = MyCounter.new([1], {}, :destination_root => File.join(destination_root, "fo[o-b]ar"))
|
91
91
|
expect(runner.relative_to_original_destination_root("bar")).to eq("bar")
|
92
92
|
end
|
93
93
|
|
@@ -114,14 +114,14 @@ describe Thor::Actions do
|
|
114
114
|
|
115
115
|
describe "#find_in_source_paths" do
|
116
116
|
it "raises an error if source path is empty" do
|
117
|
-
expect
|
117
|
+
expect do
|
118
118
|
A.new.find_in_source_paths("foo")
|
119
|
-
|
119
|
+
end.to raise_error(Thor::Error, /Currently you have no source paths/)
|
120
120
|
end
|
121
121
|
|
122
122
|
it "finds a template inside the source path" do
|
123
123
|
expect(runner.find_in_source_paths("doc")).to eq(File.expand_path("doc", source_root))
|
124
|
-
expect{ runner.find_in_source_paths("README") }.to raise_error
|
124
|
+
expect { runner.find_in_source_paths("README") }.to raise_error
|
125
125
|
|
126
126
|
new_path = File.join(source_root, "doc")
|
127
127
|
runner.instance_variable_set(:@source_paths, nil)
|
@@ -146,37 +146,37 @@ describe Thor::Actions do
|
|
146
146
|
|
147
147
|
it "creates the directory if it does not exist" do
|
148
148
|
runner.inside("foo") do
|
149
|
-
expect(File.
|
149
|
+
expect(File.exist?(file)).to be true
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
describe "when pretending" do
|
154
154
|
it "no directories should be created" do
|
155
155
|
runner.inside("bar", :pretend => true) {}
|
156
|
-
expect(File.
|
156
|
+
expect(File.exist?("bar")).to be false
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
160
|
describe "when verbose" do
|
161
161
|
it "logs status" do
|
162
|
-
expect(capture(:stdout)
|
162
|
+
expect(capture(:stdout) do
|
163
163
|
runner.inside("foo", :verbose => true) {}
|
164
|
-
|
164
|
+
end).to match(/inside foo/)
|
165
165
|
end
|
166
166
|
|
167
167
|
it "uses padding in next status" do
|
168
|
-
expect(capture(:stdout)
|
168
|
+
expect(capture(:stdout) do
|
169
169
|
runner.inside("foo", :verbose => true) do
|
170
170
|
runner.say_status :cool, :padding
|
171
171
|
end
|
172
|
-
|
172
|
+
end).to match(/cool padding/)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "removes padding after block" do
|
176
|
-
expect(capture(:stdout)
|
176
|
+
expect(capture(:stdout) do
|
177
177
|
runner.inside("foo", :verbose => true) {}
|
178
178
|
runner.say_status :no, :padding
|
179
|
-
|
179
|
+
end).to match(/no padding/)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
@@ -196,7 +196,7 @@ describe Thor::Actions do
|
|
196
196
|
|
197
197
|
it "returns to the previous state" do
|
198
198
|
runner.inside("foo") do
|
199
|
-
runner.in_root {
|
199
|
+
runner.in_root {}
|
200
200
|
expect(runner.destination_root).to eq(file)
|
201
201
|
end
|
202
202
|
end
|
@@ -208,27 +208,27 @@ describe Thor::Actions do
|
|
208
208
|
@foo = "FOO"
|
209
209
|
say_status :cool, :padding
|
210
210
|
TEMPLATE
|
211
|
-
@template.
|
211
|
+
allow(@template).to receive(:read).and_return(@template)
|
212
212
|
|
213
|
-
@file =
|
214
|
-
runner.
|
213
|
+
@file = "/"
|
214
|
+
allow(runner).to receive(:open).and_return(@template)
|
215
215
|
end
|
216
216
|
|
217
217
|
it "accepts a URL as the path" do
|
218
218
|
@file = "http://gist.github.com/103208.txt"
|
219
|
-
runner.
|
219
|
+
expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
|
220
220
|
action(:apply, @file)
|
221
221
|
end
|
222
222
|
|
223
223
|
it "accepts a secure URL as the path" do
|
224
224
|
@file = "https://gist.github.com/103208.txt"
|
225
|
-
runner.
|
225
|
+
expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
|
226
226
|
action(:apply, @file)
|
227
227
|
end
|
228
228
|
|
229
229
|
it "accepts a local file path with spaces" do
|
230
230
|
@file = File.expand_path("fixtures/path with spaces", File.dirname(__FILE__))
|
231
|
-
runner.
|
231
|
+
expect(runner).to receive(:open).with(@file).and_return(@template)
|
232
232
|
action(:apply, @file)
|
233
233
|
end
|
234
234
|
|
@@ -254,7 +254,7 @@ describe Thor::Actions do
|
|
254
254
|
|
255
255
|
describe "#run" do
|
256
256
|
before do
|
257
|
-
runner.
|
257
|
+
expect(runner).to receive(:system).with("ls")
|
258
258
|
end
|
259
259
|
|
260
260
|
it "executes the command given" do
|
@@ -270,15 +270,15 @@ describe Thor::Actions do
|
|
270
270
|
end
|
271
271
|
|
272
272
|
it "accepts a color as status" do
|
273
|
-
runner.shell.
|
273
|
+
expect(runner.shell).to receive(:say_status).with(:run, 'ls from "."', :yellow)
|
274
274
|
action :run, "ls", :verbose => :yellow
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
278
|
describe "#run_ruby_script" do
|
279
279
|
before do
|
280
|
-
Thor::Util.
|
281
|
-
runner.
|
280
|
+
allow(Thor::Util).to receive(:ruby_command).and_return("/opt/jruby")
|
281
|
+
expect(runner).to receive(:system).with("/opt/jruby script.rb")
|
282
282
|
end
|
283
283
|
|
284
284
|
it "executes the ruby script" do
|
@@ -296,35 +296,35 @@ describe Thor::Actions do
|
|
296
296
|
|
297
297
|
describe "#thor" do
|
298
298
|
it "executes the thor command" do
|
299
|
-
runner.
|
299
|
+
expect(runner).to receive(:system).with("thor list")
|
300
300
|
action :thor, :list, :verbose => true
|
301
301
|
end
|
302
302
|
|
303
303
|
it "converts extra arguments to command arguments" do
|
304
|
-
runner.
|
304
|
+
expect(runner).to receive(:system).with("thor list foo bar")
|
305
305
|
action :thor, :list, "foo", "bar"
|
306
306
|
end
|
307
307
|
|
308
308
|
it "converts options hash to switches" do
|
309
|
-
runner.
|
309
|
+
expect(runner).to receive(:system).with("thor list foo bar --foo")
|
310
310
|
action :thor, :list, "foo", "bar", :foo => true
|
311
311
|
|
312
|
-
runner.
|
313
|
-
action :thor, :list, :foo => [1,2,3]
|
312
|
+
expect(runner).to receive(:system).with("thor list --foo 1 2 3")
|
313
|
+
action :thor, :list, :foo => [1, 2, 3]
|
314
314
|
end
|
315
315
|
|
316
316
|
it "logs status" do
|
317
|
-
runner.
|
317
|
+
expect(runner).to receive(:system).with("thor list")
|
318
318
|
expect(action(:thor, :list)).to eq(" run thor list from \".\"\n")
|
319
319
|
end
|
320
320
|
|
321
321
|
it "does not log status if required" do
|
322
|
-
runner.
|
323
|
-
expect(action(:thor, :list, :foo => [1,2,3], :verbose => false)).to be_empty
|
322
|
+
expect(runner).to receive(:system).with("thor list --foo 1 2 3")
|
323
|
+
expect(action(:thor, :list, :foo => [1, 2, 3], :verbose => false)).to be_empty
|
324
324
|
end
|
325
325
|
|
326
326
|
it "captures the output when :capture is given" do
|
327
|
-
runner.
|
327
|
+
expect(runner).to receive(:`).with("thor foo bar")
|
328
328
|
action(:thor, "foo", "bar", :capture => true)
|
329
329
|
end
|
330
330
|
end
|
data/spec/base_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "helper"
|
2
|
+
require "thor/base"
|
3
3
|
|
4
4
|
class Amazing
|
5
5
|
desc "hello", "say hello"
|
@@ -36,7 +36,7 @@ describe Thor::Base do
|
|
36
36
|
|
37
37
|
it "creates options with indifferent access" do
|
38
38
|
base = MyCounter.new [1, 2], :third => 3
|
39
|
-
expect(base.options[
|
39
|
+
expect(base.options["third"]).to eq(3)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "creates options with magic predicates" do
|
@@ -54,39 +54,39 @@ describe Thor::Base do
|
|
54
54
|
|
55
55
|
describe "#argument" do
|
56
56
|
it "sets a value as required and creates an accessor for it" do
|
57
|
-
expect(MyCounter.start([
|
58
|
-
expect(Scripts::MyScript.start([
|
57
|
+
expect(MyCounter.start(%w[1 2 --third 3])[0]).to eq(1)
|
58
|
+
expect(Scripts::MyScript.start(%w[zoo my_special_param --param=normal_param])).to eq("my_special_param")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "does not set a value in the options hash" do
|
62
|
-
expect(BrokenCounter.start([
|
62
|
+
expect(BrokenCounter.start(%w[1 2 --third 3])[0]).to be nil
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "#arguments" do
|
67
67
|
it "returns the arguments for the class" do
|
68
|
-
expect(MyCounter.arguments).to
|
68
|
+
expect(MyCounter.arguments.size).to be(2)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
describe ":aliases" do
|
73
73
|
it "supports string aliases without a dash prefix" do
|
74
|
-
expect(MyCounter.start([
|
74
|
+
expect(MyCounter.start(%w[1 2 -z 3])[4]).to eq(3)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "supports symbol aliases" do
|
78
|
-
expect(MyCounter.start([
|
79
|
-
expect(MyCounter.start([
|
78
|
+
expect(MyCounter.start(%w[1 2 -y 3])[5]).to eq(3)
|
79
|
+
expect(MyCounter.start(%w[1 2 -r 3])[5]).to eq(3)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
describe "#class_option" do
|
84
84
|
it "sets options class wise" do
|
85
|
-
expect(MyCounter.start([
|
85
|
+
expect(MyCounter.start(%w[1 2 --third 3])[2]).to eq(3)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "does not create an accessor for it" do
|
89
|
-
expect(BrokenCounter.start([
|
89
|
+
expect(BrokenCounter.start(%w[1 2 --third 3])[3]).to be false
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -98,7 +98,7 @@ describe Thor::Base do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "#remove_argument" do
|
101
|
-
it "removes
|
101
|
+
it "removes previously defined arguments from class" do
|
102
102
|
expect(ClearCounter.arguments).to be_empty
|
103
103
|
end
|
104
104
|
|
@@ -110,7 +110,7 @@ describe Thor::Base do
|
|
110
110
|
|
111
111
|
describe "#remove_class_option" do
|
112
112
|
it "removes previous defined class option" do
|
113
|
-
expect(ClearCounter.class_options[:third]).to
|
113
|
+
expect(ClearCounter.class_options[:third]).to be nil
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -119,7 +119,7 @@ describe Thor::Base do
|
|
119
119
|
@content = capture(:stdout) { MyCounter.help(Thor::Base.shell.new) }
|
120
120
|
end
|
121
121
|
|
122
|
-
it "shows
|
122
|
+
it "shows option's description" do
|
123
123
|
expect(@content).to match(/# The third argument/)
|
124
124
|
end
|
125
125
|
|
@@ -127,7 +127,7 @@ describe Thor::Base do
|
|
127
127
|
expect(@content).to match(/\[\-\-third=THREE\]/)
|
128
128
|
end
|
129
129
|
|
130
|
-
it "shows default values below
|
130
|
+
it "shows default values below descriptions" do
|
131
131
|
expect(@content).to match(/# Default: 3/)
|
132
132
|
end
|
133
133
|
|
@@ -137,13 +137,13 @@ describe Thor::Base do
|
|
137
137
|
expect(@content).to match(/\-p, \[\-\-pretend\]/)
|
138
138
|
end
|
139
139
|
|
140
|
-
it "use padding in options that
|
140
|
+
it "use padding in options that do not have aliases" do
|
141
141
|
expect(@content).to match(/^ -t, \[--third/)
|
142
142
|
expect(@content).to match(/^ \[--fourth/)
|
143
143
|
end
|
144
144
|
|
145
145
|
it "allows extra options to be given" do
|
146
|
-
hash = {
|
146
|
+
hash = {"Foo" => B.class_options.values}
|
147
147
|
|
148
148
|
content = capture(:stdout) { MyCounter.send(:class_options_help, Thor::Base.shell.new, hash) }
|
149
149
|
expect(content).to match(/Foo options\:/)
|
@@ -212,10 +212,10 @@ describe Thor::Base do
|
|
212
212
|
end
|
213
213
|
|
214
214
|
it "raises an error if a command with reserved word is defined" do
|
215
|
-
expect
|
215
|
+
expect do
|
216
216
|
klass = Class.new(Thor::Group)
|
217
217
|
klass.class_eval "def shell; end"
|
218
|
-
|
218
|
+
end.to raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as command/)
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -244,48 +244,55 @@ describe Thor::Base do
|
|
244
244
|
end
|
245
245
|
|
246
246
|
describe "#start" do
|
247
|
-
it "raises an error instead of
|
247
|
+
it "raises an error instead of rescuing if THOR_DEBUG=1 is given" do
|
248
248
|
begin
|
249
|
-
ENV["THOR_DEBUG"] = 1
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
249
|
+
ENV["THOR_DEBUG"] = "1"
|
250
|
+
|
251
|
+
expect do
|
252
|
+
MyScript.start %w[what --debug]
|
253
|
+
end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.')
|
254
|
+
ensure
|
254
255
|
ENV["THOR_DEBUG"] = nil
|
255
256
|
end
|
256
257
|
end
|
257
258
|
|
259
|
+
it "raises an error instead of rescuing if :debug option is given" do
|
260
|
+
expect do
|
261
|
+
MyScript.start %w[what], :debug => true
|
262
|
+
end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.')
|
263
|
+
end
|
264
|
+
|
258
265
|
it "does not steal args" do
|
259
|
-
args = [
|
266
|
+
args = %w[foo bar --force true]
|
260
267
|
MyScript.start(args)
|
261
|
-
expect(args).to eq([
|
268
|
+
expect(args).to eq(%w[foo bar --force true])
|
262
269
|
end
|
263
270
|
|
264
271
|
it "checks unknown options" do
|
265
|
-
expect(capture(:stderr)
|
266
|
-
MyScript.start([
|
267
|
-
|
272
|
+
expect(capture(:stderr) do
|
273
|
+
MyScript.start(%w[foo bar --force true --unknown baz])
|
274
|
+
end.strip).to eq("Unknown switches '--unknown'")
|
268
275
|
end
|
269
276
|
|
270
277
|
it "checks unknown options except specified" do
|
271
|
-
expect(capture(:stderr)
|
272
|
-
expect(MyScript.start([
|
273
|
-
|
278
|
+
expect(capture(:stderr) do
|
279
|
+
expect(MyScript.start(%w[with_optional NAME --omg --invalid])).to eq(["NAME", {}, %w[--omg --invalid]])
|
280
|
+
end.strip).to be_empty
|
274
281
|
end
|
275
282
|
end
|
276
283
|
|
277
284
|
describe "attr_*" do
|
278
285
|
it "does not add attr_reader as a command" do
|
279
|
-
expect(capture(:stderr){ MyScript.start([
|
286
|
+
expect(capture(:stderr) { MyScript.start(%w[another_attribute]) }).to match(/Could not find/)
|
280
287
|
end
|
281
288
|
|
282
289
|
it "does not add attr_writer as a command" do
|
283
|
-
expect(capture(:stderr){ MyScript.start([
|
290
|
+
expect(capture(:stderr) { MyScript.start(%w[another_attribute= foo]) }).to match(/Could not find/)
|
284
291
|
end
|
285
292
|
|
286
293
|
it "does not add attr_accessor as a command" do
|
287
|
-
expect(capture(:stderr){ MyScript.start(["some_attribute"]) }).to match(/Could not find/)
|
288
|
-
expect(capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
|
294
|
+
expect(capture(:stderr) { MyScript.start(["some_attribute"]) }).to match(/Could not find/)
|
295
|
+
expect(capture(:stderr) { MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
|
289
296
|
end
|
290
297
|
end
|
291
298
|
end
|