thor 0.16.0 → 0.17.0
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/.rspec +1 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile +12 -8
- data/lib/thor.rb +79 -10
- data/lib/thor/actions.rb +13 -13
- data/lib/thor/actions/directory.rb +29 -10
- data/lib/thor/actions/file_manipulation.rb +8 -2
- data/lib/thor/base.rb +24 -11
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +5 -0
- data/lib/thor/group.rb +5 -5
- data/lib/thor/parser/options.rb +63 -25
- data/lib/thor/rake_compat.rb +3 -2
- data/lib/thor/runner.rb +1 -1
- data/lib/thor/shell/basic.rb +16 -16
- data/lib/thor/shell/color.rb +9 -9
- data/lib/thor/shell/html.rb +9 -9
- data/lib/thor/task.rb +2 -2
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +30 -30
- data/spec/actions/create_link_spec.rb +12 -12
- data/spec/actions/directory_spec.rb +34 -27
- data/spec/actions/empty_directory_spec.rb +16 -16
- data/spec/actions/file_manipulation_spec.rb +62 -50
- data/spec/actions/inject_into_file_spec.rb +18 -18
- data/spec/actions_spec.rb +56 -56
- data/spec/base_spec.rb +69 -69
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -14
- data/spec/core_ext/ordered_hash_spec.rb +29 -29
- data/spec/exit_condition_spec.rb +3 -3
- data/spec/fixtures/preserve/script.sh +3 -0
- data/spec/fixtures/script.thor +5 -0
- data/spec/group_spec.rb +55 -55
- data/spec/invocation_spec.rb +26 -26
- data/spec/parser/argument_spec.rb +12 -12
- data/spec/parser/arguments_spec.rb +12 -12
- data/spec/parser/option_spec.rb +47 -47
- data/spec/parser/options_spec.rb +137 -72
- data/spec/rake_compat_spec.rb +11 -11
- data/spec/register_spec.rb +70 -8
- data/spec/runner_spec.rb +38 -38
- data/spec/shell/basic_spec.rb +49 -37
- data/spec/shell/color_spec.rb +13 -13
- data/spec/shell/html_spec.rb +3 -3
- data/spec/shell_spec.rb +7 -7
- data/spec/spec_helper.rb +4 -0
- data/spec/task_spec.rb +11 -11
- data/spec/thor_spec.rb +161 -91
- data/spec/util_spec.rb +42 -42
- data/thor.gemspec +1 -7
- metadata +8 -118
- data/lib/thor/core_ext/dir_escape.rb +0 -0
data/spec/parser/options_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
require 'thor/parser'
|
3
3
|
|
4
4
|
describe Thor::Options do
|
5
|
-
def create(opts, defaults={})
|
5
|
+
def create(opts, defaults={}, stop_on_unknown=false)
|
6
6
|
opts.each do |key, value|
|
7
7
|
opts[key] = Thor::Option.parse(key, value) unless value.is_a?(Thor::Option)
|
8
8
|
end
|
9
9
|
|
10
|
-
@opt = Thor::Options.new(opts, defaults)
|
10
|
+
@opt = Thor::Options.new(opts, defaults, stop_on_unknown)
|
11
11
|
end
|
12
12
|
|
13
13
|
def parse(*args)
|
@@ -18,38 +18,42 @@ describe Thor::Options do
|
|
18
18
|
@opt.check_unknown!
|
19
19
|
end
|
20
20
|
|
21
|
+
def remaining
|
22
|
+
@opt.remaining
|
23
|
+
end
|
24
|
+
|
21
25
|
describe "#to_switches" do
|
22
26
|
it "turns true values into a flag" do
|
23
|
-
Thor::Options.to_switches(:color => true).
|
27
|
+
expect(Thor::Options.to_switches(:color => true)).to eq("--color")
|
24
28
|
end
|
25
29
|
|
26
30
|
it "ignores nil" do
|
27
|
-
Thor::Options.to_switches(:color => nil).
|
31
|
+
expect(Thor::Options.to_switches(:color => nil)).to eq("")
|
28
32
|
end
|
29
33
|
|
30
34
|
it "ignores false" do
|
31
|
-
Thor::Options.to_switches(:color => false).
|
35
|
+
expect(Thor::Options.to_switches(:color => false)).to eq("")
|
32
36
|
end
|
33
37
|
|
34
38
|
it "writes --name value for anything else" do
|
35
|
-
Thor::Options.to_switches(:format => "specdoc").
|
39
|
+
expect(Thor::Options.to_switches(:format => "specdoc")).to eq('--format "specdoc"')
|
36
40
|
end
|
37
41
|
|
38
42
|
it "joins several values" do
|
39
43
|
switches = Thor::Options.to_switches(:color => true, :foo => "bar").split(' ').sort
|
40
|
-
switches.
|
44
|
+
expect(switches).to eq(['"bar"', "--color", "--foo"])
|
41
45
|
end
|
42
46
|
|
43
47
|
it "accepts arrays" do
|
44
|
-
Thor::Options.to_switches(:count => [1,2,3]).
|
48
|
+
expect(Thor::Options.to_switches(:count => [1,2,3])).to eq("--count 1 2 3")
|
45
49
|
end
|
46
50
|
|
47
51
|
it "accepts hashes" do
|
48
|
-
Thor::Options.to_switches(:count => {:a => :b}).
|
52
|
+
expect(Thor::Options.to_switches(:count => {:a => :b})).to eq("--count a:b")
|
49
53
|
end
|
50
54
|
|
51
55
|
it "accepts underscored options" do
|
52
|
-
Thor::Options.to_switches(:under_score_option => "foo bar").
|
56
|
+
expect(Thor::Options.to_switches(:under_score_option => "foo bar")).to eq('--under_score_option "foo bar"')
|
53
57
|
end
|
54
58
|
|
55
59
|
end
|
@@ -57,96 +61,126 @@ describe Thor::Options do
|
|
57
61
|
describe "#parse" do
|
58
62
|
it "allows multiple aliases for a given switch" do
|
59
63
|
create ["--foo", "--bar", "--baz"] => :string
|
60
|
-
parse("--foo", "12")["foo"].
|
61
|
-
parse("--bar", "12")["foo"].
|
62
|
-
parse("--baz", "12")["foo"].
|
64
|
+
expect(parse("--foo", "12")["foo"]).to eq("12")
|
65
|
+
expect(parse("--bar", "12")["foo"]).to eq("12")
|
66
|
+
expect(parse("--baz", "12")["foo"]).to eq("12")
|
63
67
|
end
|
64
68
|
|
65
69
|
it "allows custom short names" do
|
66
70
|
create "-f" => :string
|
67
|
-
parse("-f", "12").
|
71
|
+
expect(parse("-f", "12")).to eq({"f" => "12"})
|
68
72
|
end
|
69
73
|
|
70
74
|
it "allows custom short-name aliases" do
|
71
75
|
create ["--bar", "-f"] => :string
|
72
|
-
parse("-f", "12").
|
76
|
+
expect(parse("-f", "12")).to eq({"bar" => "12"})
|
73
77
|
end
|
74
78
|
|
75
79
|
it "accepts conjoined short switches" do
|
76
80
|
create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => true
|
77
81
|
opts = parse("-fba")
|
78
|
-
opts["foo"].
|
79
|
-
opts["bar"].
|
80
|
-
opts["app"].
|
82
|
+
expect(opts["foo"]).to be_true
|
83
|
+
expect(opts["bar"]).to be_true
|
84
|
+
expect(opts["app"]).to be_true
|
81
85
|
end
|
82
86
|
|
83
87
|
it "accepts conjoined short switches with input" do
|
84
88
|
create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => :required
|
85
89
|
opts = parse "-fba", "12"
|
86
|
-
opts["foo"].
|
87
|
-
opts["bar"].
|
88
|
-
opts["app"].
|
90
|
+
expect(opts["foo"]).to be_true
|
91
|
+
expect(opts["bar"]).to be_true
|
92
|
+
expect(opts["app"]).to eq("12")
|
89
93
|
end
|
90
94
|
|
91
95
|
it "returns the default value if none is provided" do
|
92
96
|
create :foo => "baz", :bar => :required
|
93
|
-
parse("--bar", "boom")["foo"].
|
97
|
+
expect(parse("--bar", "boom")["foo"]).to eq("baz")
|
94
98
|
end
|
95
99
|
|
96
100
|
it "returns the default value from defaults hash to required arguments" do
|
97
101
|
create Hash[:bar => :required], Hash[:bar => "baz"]
|
98
|
-
parse["bar"].
|
102
|
+
expect(parse["bar"]).to eq("baz")
|
99
103
|
end
|
100
104
|
|
101
105
|
it "gives higher priority to defaults given in the hash" do
|
102
106
|
create Hash[:bar => true], Hash[:bar => false]
|
103
|
-
parse["bar"].
|
107
|
+
expect(parse["bar"]).to eq(false)
|
104
108
|
end
|
105
109
|
|
106
110
|
it "raises an error for unknown switches" do
|
107
111
|
create :foo => "baz", :bar => :required
|
108
112
|
parse("--bar", "baz", "--baz", "unknown")
|
109
|
-
|
113
|
+
expect{ check_unknown! }.to raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'")
|
110
114
|
end
|
111
115
|
|
112
116
|
it "skips leading non-switches" do
|
113
117
|
create(:foo => "baz")
|
114
118
|
|
115
|
-
parse("asdf", "--foo", "bar").
|
119
|
+
expect(parse("asdf", "--foo", "bar")).to eq({"foo" => "bar"})
|
116
120
|
end
|
117
121
|
|
118
122
|
it "correctly recognizes things that look kind of like options, but aren't, as not options" do
|
119
123
|
create(:foo => "baz")
|
120
|
-
parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").
|
124
|
+
expect(parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf")).to eq({"foo" => "--asdf---dsf--asdf"})
|
121
125
|
check_unknown!
|
122
126
|
end
|
123
127
|
|
124
128
|
it "accepts underscores in commandline args hash for boolean" do
|
125
129
|
create :foo_bar => :boolean
|
126
|
-
parse("--foo_bar")["foo_bar"].
|
127
|
-
parse("--no_foo_bar")["foo_bar"].
|
130
|
+
expect(parse("--foo_bar")["foo_bar"]).to eq(true)
|
131
|
+
expect(parse("--no_foo_bar")["foo_bar"]).to eq(false)
|
128
132
|
end
|
129
133
|
|
130
134
|
it "accepts underscores in commandline args hash for strings" do
|
131
135
|
create :foo_bar => :string, :baz_foo => :string
|
132
|
-
parse("--foo_bar", "baz")["foo_bar"].
|
133
|
-
parse("--baz_foo", "foo bar")["baz_foo"].
|
136
|
+
expect(parse("--foo_bar", "baz")["foo_bar"]).to eq("baz")
|
137
|
+
expect(parse("--baz_foo", "foo bar")["baz_foo"]).to eq("foo bar")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "interprets everything after -- as args instead of options" do
|
141
|
+
create(:foo => :string, :bar => :required)
|
142
|
+
expect(parse(%w[--bar abc moo -- --foo def -a])).to eq({"bar" => "abc"})
|
143
|
+
expect(remaining).to eq(%w[moo --foo def -a])
|
144
|
+
end
|
145
|
+
|
146
|
+
it "ignores -- when looking for single option values" do
|
147
|
+
create(:foo => :string, :bar => :required)
|
148
|
+
expect(parse(%w[--bar -- --foo def -a])).to eq({"bar" => "--foo"})
|
149
|
+
expect(remaining).to eq(%w[def -a])
|
150
|
+
end
|
151
|
+
|
152
|
+
it "ignores -- when looking for array option values" do
|
153
|
+
create(:foo => :array)
|
154
|
+
expect(parse(%w[--foo a b -- c d -e])).to eq({"foo" => %w[a b c d -e]})
|
155
|
+
expect(remaining).to eq([])
|
156
|
+
end
|
157
|
+
|
158
|
+
it "ignores -- when looking for hash option values" do
|
159
|
+
create(:foo => :hash)
|
160
|
+
expect(parse(%w[--foo a:b -- c:d -e])).to eq({"foo" => {'a' => 'b', 'c' => 'd'}})
|
161
|
+
expect(remaining).to eq(%w[-e])
|
162
|
+
end
|
163
|
+
|
164
|
+
it "ignores trailing --" do
|
165
|
+
create(:foo => :string)
|
166
|
+
expect(parse(%w[--foo --])).to eq({"foo" => nil})
|
167
|
+
expect(remaining).to eq([])
|
134
168
|
end
|
135
169
|
|
136
170
|
describe "with no input" do
|
137
171
|
it "and no switches returns an empty hash" do
|
138
172
|
create({})
|
139
|
-
parse.
|
173
|
+
expect(parse).to eq({})
|
140
174
|
end
|
141
175
|
|
142
176
|
it "and several switches returns an empty hash" do
|
143
177
|
create "--foo" => :boolean, "--bar" => :string
|
144
|
-
parse.
|
178
|
+
expect(parse).to eq({})
|
145
179
|
end
|
146
180
|
|
147
181
|
it "and a required switch raises an error" do
|
148
182
|
create "--foo" => :required
|
149
|
-
|
183
|
+
expect{ parse }.to raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'")
|
150
184
|
end
|
151
185
|
end
|
152
186
|
|
@@ -156,21 +190,52 @@ describe Thor::Options do
|
|
156
190
|
end
|
157
191
|
|
158
192
|
it "raises an error if the required switch has no argument" do
|
159
|
-
|
193
|
+
expect{ parse("--foo") }.to raise_error(Thor::MalformattedArgumentError)
|
160
194
|
end
|
161
195
|
|
162
196
|
it "raises an error if the required switch isn't given" do
|
163
|
-
|
197
|
+
expect{ parse("--bar") }.to raise_error(Thor::RequiredArgumentMissingError)
|
164
198
|
end
|
165
199
|
|
166
200
|
it "raises an error if the required switch is set to nil" do
|
167
|
-
|
201
|
+
expect{ parse("--no-foo") }.to raise_error(Thor::RequiredArgumentMissingError)
|
168
202
|
end
|
169
203
|
|
170
204
|
it "does not raises an error if the required option has a default value" do
|
171
205
|
options = {:required => true, :type => :string, :default => "baz"}
|
172
206
|
create :foo => Thor::Option.new("foo", options), :bar => :boolean
|
173
|
-
|
207
|
+
expect{ parse("--bar") }.not_to raise_error
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context "when stop_on_unknown is true" do
|
212
|
+
before do
|
213
|
+
create({:foo => :string, :verbose => :boolean}, {}, true)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "stops parsing on first non-option" do
|
217
|
+
expect(parse(%w[foo --verbose])).to eq({})
|
218
|
+
expect(remaining).to eq(["foo", "--verbose"])
|
219
|
+
end
|
220
|
+
|
221
|
+
it "stops parsing on unknown option" do
|
222
|
+
expect(parse(%w[--bar --verbose])).to eq({})
|
223
|
+
expect(remaining).to eq(["--bar", "--verbose"])
|
224
|
+
end
|
225
|
+
|
226
|
+
it "still accepts options that are given before non-options" do
|
227
|
+
expect(parse(%w[--verbose foo])).to eq({"verbose" => true})
|
228
|
+
expect(remaining).to eq(["foo"])
|
229
|
+
end
|
230
|
+
|
231
|
+
it "still accepts options that require a value" do
|
232
|
+
expect(parse(%w[--foo bar baz])).to eq({"foo" => "bar"})
|
233
|
+
expect(remaining).to eq(["baz"])
|
234
|
+
end
|
235
|
+
|
236
|
+
it "still interprets everything after -- as args instead of options" do
|
237
|
+
expect(parse(%w[-- --verbose])).to eq({})
|
238
|
+
expect(remaining).to eq(["--verbose"])
|
174
239
|
end
|
175
240
|
end
|
176
241
|
|
@@ -180,43 +245,43 @@ describe Thor::Options do
|
|
180
245
|
end
|
181
246
|
|
182
247
|
it "accepts a switch <value> assignment" do
|
183
|
-
parse("--foo", "12")["foo"].
|
248
|
+
expect(parse("--foo", "12")["foo"]).to eq("12")
|
184
249
|
end
|
185
250
|
|
186
251
|
it "accepts a switch=<value> assignment" do
|
187
|
-
parse("-f=12")["foo"].
|
188
|
-
parse("--foo=12")["foo"].
|
189
|
-
parse("--foo=bar=baz")["foo"].
|
252
|
+
expect(parse("-f=12")["foo"]).to eq("12")
|
253
|
+
expect(parse("--foo=12")["foo"]).to eq("12")
|
254
|
+
expect(parse("--foo=bar=baz")["foo"]).to eq("bar=baz")
|
190
255
|
end
|
191
256
|
|
192
257
|
it "must accept underscores switch=value assignment" do
|
193
258
|
create :foo_bar => :required
|
194
|
-
parse("--foo_bar=http://example.com/under_score/")["foo_bar"].
|
259
|
+
expect(parse("--foo_bar=http://example.com/under_score/")["foo_bar"]).to eq("http://example.com/under_score/")
|
195
260
|
end
|
196
261
|
|
197
262
|
it "accepts a --no-switch format" do
|
198
263
|
create "--foo" => "bar"
|
199
|
-
parse("--no-foo")["foo"].
|
264
|
+
expect(parse("--no-foo")["foo"]).to be_nil
|
200
265
|
end
|
201
266
|
|
202
267
|
it "does not consume an argument for --no-switch format" do
|
203
268
|
create "--cheese" => :string
|
204
|
-
parse('burger', '--no-cheese', 'fries')["cheese"].
|
269
|
+
expect(parse('burger', '--no-cheese', 'fries')["cheese"]).to be_nil
|
205
270
|
end
|
206
271
|
|
207
272
|
it "accepts a --switch format on non required types" do
|
208
273
|
create "--foo" => :string
|
209
|
-
parse("--foo")["foo"].
|
274
|
+
expect(parse("--foo")["foo"]).to eq("foo")
|
210
275
|
end
|
211
276
|
|
212
277
|
it "accepts a --switch format on non required types with default values" do
|
213
278
|
create "--baz" => :string, "--foo" => "bar"
|
214
|
-
parse("--baz", "bang", "--foo")["foo"].
|
279
|
+
expect(parse("--baz", "bang", "--foo")["foo"]).to eq("bar")
|
215
280
|
end
|
216
281
|
|
217
282
|
it "overwrites earlier values with later values" do
|
218
|
-
parse("--foo=bar", "--foo", "12")["foo"].
|
219
|
-
parse("--foo", "12", "--foo", "13")["foo"].
|
283
|
+
expect(parse("--foo=bar", "--foo", "12")["foo"]).to eq("12")
|
284
|
+
expect(parse("--foo", "12", "--foo", "13")["foo"]).to eq("13")
|
220
285
|
end
|
221
286
|
end
|
222
287
|
|
@@ -226,48 +291,48 @@ describe Thor::Options do
|
|
226
291
|
end
|
227
292
|
|
228
293
|
it "accepts --opt assignment" do
|
229
|
-
parse("--foo")["foo"].
|
230
|
-
parse("--foo", "--bar")["foo"].
|
294
|
+
expect(parse("--foo")["foo"]).to eq(true)
|
295
|
+
expect(parse("--foo", "--bar")["foo"]).to eq(true)
|
231
296
|
end
|
232
297
|
|
233
298
|
it "uses the default value if no switch is given" do
|
234
|
-
parse("")["foo"].
|
299
|
+
expect(parse("")["foo"]).to eq(false)
|
235
300
|
end
|
236
301
|
|
237
302
|
it "accepts --opt=value assignment" do
|
238
|
-
parse("--foo=true")["foo"].
|
239
|
-
parse("--foo=false")["foo"].
|
303
|
+
expect(parse("--foo=true")["foo"]).to eq(true)
|
304
|
+
expect(parse("--foo=false")["foo"]).to eq(false)
|
240
305
|
end
|
241
306
|
|
242
307
|
it "accepts --[no-]opt variant, setting false for value" do
|
243
|
-
parse("--no-foo")["foo"].
|
308
|
+
expect(parse("--no-foo")["foo"]).to eq(false)
|
244
309
|
end
|
245
310
|
|
246
311
|
it "accepts --[skip-]opt variant, setting false for value" do
|
247
|
-
parse("--skip-foo")["foo"].
|
312
|
+
expect(parse("--skip-foo")["foo"]).to eq(false)
|
248
313
|
end
|
249
314
|
|
250
315
|
it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do
|
251
316
|
create "--no-foo" => true
|
252
|
-
parse("--no-foo")["no-foo"].
|
317
|
+
expect(parse("--no-foo")["no-foo"]).to eq(true)
|
253
318
|
end
|
254
319
|
|
255
320
|
it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do
|
256
321
|
create "--skip-foo" => true
|
257
|
-
parse("--skip-foo")["skip-foo"].
|
322
|
+
expect(parse("--skip-foo")["skip-foo"]).to eq(true)
|
258
323
|
end
|
259
324
|
|
260
325
|
it "accepts inputs in the human name format" do
|
261
326
|
create :foo_bar => :boolean
|
262
|
-
parse("--foo-bar")["foo_bar"].
|
263
|
-
parse("--no-foo-bar")["foo_bar"].
|
264
|
-
parse("--skip-foo-bar")["foo_bar"].
|
327
|
+
expect(parse("--foo-bar")["foo_bar"]).to eq(true)
|
328
|
+
expect(parse("--no-foo-bar")["foo_bar"]).to eq(false)
|
329
|
+
expect(parse("--skip-foo-bar")["foo_bar"]).to eq(false)
|
265
330
|
end
|
266
331
|
|
267
332
|
it "doesn't eat the next part of the param" do
|
268
333
|
create :foo => :boolean
|
269
|
-
parse("--foo", "bar").
|
270
|
-
@opt.remaining.
|
334
|
+
expect(parse("--foo", "bar")).to eq({"foo" => true})
|
335
|
+
expect(@opt.remaining).to eq(["bar"])
|
271
336
|
end
|
272
337
|
end
|
273
338
|
|
@@ -277,15 +342,15 @@ describe Thor::Options do
|
|
277
342
|
end
|
278
343
|
|
279
344
|
it "accepts a switch=<value> assignment" do
|
280
|
-
parse("--attributes=name:string", "age:integer")["attributes"].
|
345
|
+
expect(parse("--attributes=name:string", "age:integer")["attributes"]).to eq({"name" => "string", "age" => "integer"})
|
281
346
|
end
|
282
347
|
|
283
348
|
it "accepts a switch <value> assignment" do
|
284
|
-
parse("--attributes", "name:string", "age:integer")["attributes"].
|
349
|
+
expect(parse("--attributes", "name:string", "age:integer")["attributes"]).to eq({"name" => "string", "age" => "integer"})
|
285
350
|
end
|
286
351
|
|
287
352
|
it "must not mix values with other switches" do
|
288
|
-
parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].
|
353
|
+
expect(parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"]).to eq({"name" => "string", "age" => "integer"})
|
289
354
|
end
|
290
355
|
end
|
291
356
|
|
@@ -295,15 +360,15 @@ describe Thor::Options do
|
|
295
360
|
end
|
296
361
|
|
297
362
|
it "accepts a switch=<value> assignment" do
|
298
|
-
parse("--attributes=a", "b", "c")["attributes"].
|
363
|
+
expect(parse("--attributes=a", "b", "c")["attributes"]).to eq(["a", "b", "c"])
|
299
364
|
end
|
300
365
|
|
301
366
|
it "accepts a switch <value> assignment" do
|
302
|
-
parse("--attributes", "a", "b", "c")["attributes"].
|
367
|
+
expect(parse("--attributes", "a", "b", "c")["attributes"]).to eq(["a", "b", "c"])
|
303
368
|
end
|
304
369
|
|
305
370
|
it "must not mix values with other switches" do
|
306
|
-
parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].
|
371
|
+
expect(parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"]).to eq(["a", "b", "c"])
|
307
372
|
end
|
308
373
|
end
|
309
374
|
|
@@ -313,15 +378,15 @@ describe Thor::Options do
|
|
313
378
|
end
|
314
379
|
|
315
380
|
it "accepts a -nXY assignment" do
|
316
|
-
parse("-n12")["n"].
|
381
|
+
expect(parse("-n12")["n"]).to eq(12)
|
317
382
|
end
|
318
383
|
|
319
384
|
it "converts values to numeric types" do
|
320
|
-
parse("-n", "3", "-m", ".5").
|
385
|
+
expect(parse("-n", "3", "-m", ".5")).to eq({"n" => 3, "m" => 0.5})
|
321
386
|
end
|
322
387
|
|
323
388
|
it "raises error when value isn't numeric" do
|
324
|
-
|
389
|
+
expect{ parse("-n", "foo") }.to raise_error(Thor::MalformattedArgumentError,
|
325
390
|
"Expected numeric value for '-n'; got \"foo\"")
|
326
391
|
end
|
327
392
|
end
|
data/spec/rake_compat_spec.rb
CHANGED
@@ -32,41 +32,41 @@ end
|
|
32
32
|
|
33
33
|
describe Thor::RakeCompat do
|
34
34
|
it "sets the rakefile application" do
|
35
|
-
["rake_compat_spec.rb", "Thorfile"].
|
35
|
+
expect(["rake_compat_spec.rb", "Thorfile"]).to include(Rake.application.rakefile)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "adds rake tasks to thor classes too" do
|
39
39
|
task = ThorTask.tasks["cool"]
|
40
|
-
task.
|
40
|
+
expect(task).to be
|
41
41
|
end
|
42
42
|
|
43
43
|
it "uses rake tasks descriptions on thor" do
|
44
|
-
ThorTask.tasks["cool"].description.
|
44
|
+
expect(ThorTask.tasks["cool"].description).to eq("Say it's cool")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "gets usage from rake tasks name" do
|
48
|
-
ThorTask.tasks["cool"].usage.
|
48
|
+
expect(ThorTask.tasks["cool"].usage).to eq("cool")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "uses non namespaced name as description if non is available" do
|
52
|
-
ThorTask::HiperMega.tasks["super"].description.
|
52
|
+
expect(ThorTask::HiperMega.tasks["super"].description).to eq("super")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "converts namespaces to classes" do
|
56
|
-
ThorTask.const_get(:HiperMega).
|
56
|
+
expect(ThorTask.const_get(:HiperMega)).to eq(ThorTask::HiperMega)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "does not add tasks from higher namespaces in lowers namespaces" do
|
60
|
-
ThorTask.tasks["super"].
|
60
|
+
expect(ThorTask.tasks["super"]).not_to be
|
61
61
|
end
|
62
62
|
|
63
63
|
it "invoking the thor task invokes the rake task" do
|
64
|
-
capture(:stdout)
|
64
|
+
expect(capture(:stdout) {
|
65
65
|
ThorTask.start ["cool"]
|
66
|
-
|
66
|
+
}).to eq("COOL\n")
|
67
67
|
|
68
|
-
capture(:stdout)
|
68
|
+
expect(capture(:stdout) {
|
69
69
|
ThorTask::HiperMega.start ["super"]
|
70
|
-
|
70
|
+
}).to eq("HIPER MEGA SUPER\n")
|
71
71
|
end
|
72
72
|
end
|