thor 0.14.4 → 0.14.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,133 +20,133 @@ describe Thor::Options do
20
20
 
21
21
  describe "#to_switches" do
22
22
  it "turns true values into a flag" do
23
- Thor::Options.to_switches(:color => true).must == "--color"
23
+ Thor::Options.to_switches(:color => true).should == "--color"
24
24
  end
25
25
 
26
26
  it "ignores nil" do
27
- Thor::Options.to_switches(:color => nil).must == ""
27
+ Thor::Options.to_switches(:color => nil).should == ""
28
28
  end
29
29
 
30
30
  it "ignores false" do
31
- Thor::Options.to_switches(:color => false).must == ""
31
+ Thor::Options.to_switches(:color => false).should == ""
32
32
  end
33
33
 
34
34
  it "writes --name value for anything else" do
35
- Thor::Options.to_switches(:format => "specdoc").must == '--format "specdoc"'
35
+ Thor::Options.to_switches(:format => "specdoc").should == '--format "specdoc"'
36
36
  end
37
37
 
38
38
  it "joins several values" do
39
39
  switches = Thor::Options.to_switches(:color => true, :foo => "bar").split(' ').sort
40
- switches.must == ['"bar"', "--color", "--foo"]
40
+ switches.should == ['"bar"', "--color", "--foo"]
41
41
  end
42
42
 
43
43
  it "accepts arrays" do
44
- Thor::Options.to_switches(:count => [1,2,3]).must == "--count 1 2 3"
44
+ Thor::Options.to_switches(:count => [1,2,3]).should == "--count 1 2 3"
45
45
  end
46
46
 
47
47
  it "accepts hashes" do
48
- Thor::Options.to_switches(:count => {:a => :b}).must == "--count a:b"
48
+ Thor::Options.to_switches(:count => {:a => :b}).should == "--count a:b"
49
49
  end
50
-
50
+
51
51
  it "accepts underscored options" do
52
- Thor::Options.to_switches(:under_score_option => "foo bar").must == '--under_score_option "foo bar"'
52
+ Thor::Options.to_switches(:under_score_option => "foo bar").should == '--under_score_option "foo bar"'
53
53
  end
54
-
54
+
55
55
  end
56
56
 
57
57
  describe "#parse" do
58
58
  it "allows multiple aliases for a given switch" do
59
59
  create ["--foo", "--bar", "--baz"] => :string
60
- parse("--foo", "12")["foo"].must == "12"
61
- parse("--bar", "12")["foo"].must == "12"
62
- parse("--baz", "12")["foo"].must == "12"
60
+ parse("--foo", "12")["foo"].should == "12"
61
+ parse("--bar", "12")["foo"].should == "12"
62
+ parse("--baz", "12")["foo"].should == "12"
63
63
  end
64
64
 
65
65
  it "allows custom short names" do
66
66
  create "-f" => :string
67
- parse("-f", "12").must == {"f" => "12"}
67
+ parse("-f", "12").should == {"f" => "12"}
68
68
  end
69
69
 
70
70
  it "allows custom short-name aliases" do
71
71
  create ["--bar", "-f"] => :string
72
- parse("-f", "12").must == {"bar" => "12"}
72
+ parse("-f", "12").should == {"bar" => "12"}
73
73
  end
74
74
 
75
75
  it "accepts conjoined short switches" do
76
76
  create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => true
77
77
  opts = parse("-fba")
78
- opts["foo"].must be_true
79
- opts["bar"].must be_true
80
- opts["app"].must be_true
78
+ opts["foo"].should be_true
79
+ opts["bar"].should be_true
80
+ opts["app"].should be_true
81
81
  end
82
82
 
83
83
  it "accepts conjoined short switches with input" do
84
84
  create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => :required
85
85
  opts = parse "-fba", "12"
86
- opts["foo"].must be_true
87
- opts["bar"].must be_true
88
- opts["app"].must == "12"
86
+ opts["foo"].should be_true
87
+ opts["bar"].should be_true
88
+ opts["app"].should == "12"
89
89
  end
90
90
 
91
91
  it "returns the default value if none is provided" do
92
92
  create :foo => "baz", :bar => :required
93
- parse("--bar", "boom")["foo"].must == "baz"
93
+ parse("--bar", "boom")["foo"].should == "baz"
94
94
  end
95
95
 
96
96
  it "returns the default value from defaults hash to required arguments" do
97
97
  create Hash[:bar => :required], Hash[:bar => "baz"]
98
- parse["bar"].must == "baz"
98
+ parse["bar"].should == "baz"
99
99
  end
100
100
 
101
101
  it "gives higher priority to defaults given in the hash" do
102
102
  create Hash[:bar => true], Hash[:bar => false]
103
- parse["bar"].must == false
103
+ parse["bar"].should == false
104
104
  end
105
105
 
106
106
  it "raises an error for unknown switches" do
107
107
  create :foo => "baz", :bar => :required
108
108
  parse("--bar", "baz", "--baz", "unknown")
109
- lambda { check_unknown! }.must raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'")
109
+ lambda { check_unknown! }.should raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'")
110
110
  end
111
-
111
+
112
112
  it "skips leading non-switches" do
113
113
  create(:foo => "baz")
114
-
115
- parse("asdf", "--foo", "bar").must == {"foo" => "bar"}
114
+
115
+ parse("asdf", "--foo", "bar").should == {"foo" => "bar"}
116
116
  end
117
117
 
118
118
  it "correctly recognizes things that look kind of like options, but aren't, as not options" do
119
119
  create(:foo => "baz")
120
- parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").must == {"foo" => "--asdf---dsf--asdf"}
120
+ parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").should == {"foo" => "--asdf---dsf--asdf"}
121
121
  check_unknown!
122
122
  end
123
-
123
+
124
124
  it "excepts underscores in commandline args hash for boolean" do
125
125
  create :foo_bar => :boolean
126
- parse("--foo_bar")["foo_bar"].must == true
127
- parse("--no_foo_bar")["foo_bar"].must == false
126
+ parse("--foo_bar")["foo_bar"].should == true
127
+ parse("--no_foo_bar")["foo_bar"].should == false
128
128
  end
129
-
129
+
130
130
  it "excepts underscores in commandline args hash for strings" do
131
131
  create :foo_bar => :string, :baz_foo => :string
132
- parse("--foo_bar", "baz")["foo_bar"].must == "baz"
133
- parse("--baz_foo", "foo bar")["baz_foo"].must == "foo bar"
132
+ parse("--foo_bar", "baz")["foo_bar"].should == "baz"
133
+ parse("--baz_foo", "foo bar")["baz_foo"].should == "foo bar"
134
134
  end
135
135
 
136
136
  describe "with no input" do
137
137
  it "and no switches returns an empty hash" do
138
138
  create({})
139
- parse.must == {}
139
+ parse.should == {}
140
140
  end
141
141
 
142
142
  it "and several switches returns an empty hash" do
143
143
  create "--foo" => :boolean, "--bar" => :string
144
- parse.must == {}
144
+ parse.should == {}
145
145
  end
146
146
 
147
147
  it "and a required switch raises an error" do
148
148
  create "--foo" => :required
149
- lambda { parse }.must raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'")
149
+ lambda { parse }.should raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'")
150
150
  end
151
151
  end
152
152
 
@@ -156,20 +156,20 @@ describe Thor::Options do
156
156
  end
157
157
 
158
158
  it "raises an error if the required switch has no argument" do
159
- lambda { parse("--foo") }.must raise_error(Thor::MalformattedArgumentError)
159
+ lambda { parse("--foo") }.should raise_error(Thor::MalformattedArgumentError)
160
160
  end
161
161
 
162
162
  it "raises an error if the required switch isn't given" do
163
- lambda { parse("--bar") }.must raise_error(Thor::RequiredArgumentMissingError)
163
+ lambda { parse("--bar") }.should raise_error(Thor::RequiredArgumentMissingError)
164
164
  end
165
165
 
166
166
  it "raises an error if the required switch is set to nil" do
167
- lambda { parse("--no-foo") }.must raise_error(Thor::RequiredArgumentMissingError)
167
+ lambda { parse("--no-foo") }.should raise_error(Thor::RequiredArgumentMissingError)
168
168
  end
169
169
 
170
170
  it "does not raises an error if the required option has a default value" do
171
171
  create :foo => Thor::Option.new("foo", nil, true, :string, "baz"), :bar => :boolean
172
- lambda { parse("--bar") }.must_not raise_error
172
+ lambda { parse("--bar") }.should_not raise_error
173
173
  end
174
174
  end
175
175
 
@@ -179,43 +179,43 @@ describe Thor::Options do
179
179
  end
180
180
 
181
181
  it "accepts a switch <value> assignment" do
182
- parse("--foo", "12")["foo"].must == "12"
182
+ parse("--foo", "12")["foo"].should == "12"
183
183
  end
184
184
 
185
185
  it "accepts a switch=<value> assignment" do
186
- parse("-f=12")["foo"].must == "12"
187
- parse("--foo=12")["foo"].must == "12"
188
- parse("--foo=bar=baz")["foo"].must == "bar=baz"
186
+ parse("-f=12")["foo"].should == "12"
187
+ parse("--foo=12")["foo"].should == "12"
188
+ parse("--foo=bar=baz")["foo"].should == "bar=baz"
189
189
  end
190
-
190
+
191
191
  it "must accept underscores switch=value assignment" do
192
192
  create :foo_bar => :required
193
- parse("--foo_bar=http://example.com/under_score/")["foo_bar"].must == "http://example.com/under_score/"
193
+ parse("--foo_bar=http://example.com/under_score/")["foo_bar"].should == "http://example.com/under_score/"
194
194
  end
195
195
 
196
196
  it "accepts a --no-switch format" do
197
197
  create "--foo" => "bar"
198
- parse("--no-foo")["foo"].must be_nil
198
+ parse("--no-foo")["foo"].should be_nil
199
199
  end
200
200
 
201
201
  it "does not consume an argument for --no-switch format" do
202
202
  create "--cheese" => :string
203
- parse('burger', '--no-cheese', 'fries')["cheese"].must be_nil
203
+ parse('burger', '--no-cheese', 'fries')["cheese"].should be_nil
204
204
  end
205
205
 
206
206
  it "accepts a --switch format on non required types" do
207
207
  create "--foo" => :string
208
- parse("--foo")["foo"].must == "foo"
208
+ parse("--foo")["foo"].should == "foo"
209
209
  end
210
-
210
+
211
211
  it "accepts a --switch format on non required types with default values" do
212
212
  create "--baz" => :string, "--foo" => "bar"
213
- parse("--baz", "bang", "--foo")["foo"].must == "bar"
213
+ parse("--baz", "bang", "--foo")["foo"].should == "bar"
214
214
  end
215
215
 
216
216
  it "overwrites earlier values with later values" do
217
- parse("--foo=bar", "--foo", "12")["foo"].must == "12"
218
- parse("--foo", "12", "--foo", "13")["foo"].must == "13"
217
+ parse("--foo=bar", "--foo", "12")["foo"].should == "12"
218
+ parse("--foo", "12", "--foo", "13")["foo"].should == "13"
219
219
  end
220
220
  end
221
221
 
@@ -225,38 +225,38 @@ describe Thor::Options do
225
225
  end
226
226
 
227
227
  it "accepts --opt assignment" do
228
- parse("--foo")["foo"].must == true
229
- parse("--foo", "--bar")["foo"].must == true
228
+ parse("--foo")["foo"].should == true
229
+ parse("--foo", "--bar")["foo"].should == true
230
230
  end
231
231
 
232
232
  it "accepts --opt=value assignment" do
233
- parse("--foo=true")["foo"].must == true
234
- parse("--foo=false")["foo"].must == false
233
+ parse("--foo=true")["foo"].should == true
234
+ parse("--foo=false")["foo"].should == false
235
235
  end
236
236
 
237
237
  it "accepts --[no-]opt variant, setting false for value" do
238
- parse("--no-foo")["foo"].must == false
238
+ parse("--no-foo")["foo"].should == false
239
239
  end
240
240
 
241
241
  it "accepts --[skip-]opt variant, setting false for value" do
242
- parse("--skip-foo")["foo"].must == false
242
+ parse("--skip-foo")["foo"].should == false
243
243
  end
244
244
 
245
245
  it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do
246
246
  create "--no-foo" => true
247
- parse("--no-foo")["no-foo"].must == true
247
+ parse("--no-foo")["no-foo"].should == true
248
248
  end
249
249
 
250
250
  it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do
251
251
  create "--skip-foo" => true
252
- parse("--skip-foo")["skip-foo"].must == true
252
+ parse("--skip-foo")["skip-foo"].should == true
253
253
  end
254
254
 
255
255
  it "accepts inputs in the human name format" do
256
256
  create :foo_bar => :boolean
257
- parse("--foo-bar")["foo_bar"].must == true
258
- parse("--no-foo-bar")["foo_bar"].must == false
259
- parse("--skip-foo-bar")["foo_bar"].must == false
257
+ parse("--foo-bar")["foo_bar"].should == true
258
+ parse("--no-foo-bar")["foo_bar"].should == false
259
+ parse("--skip-foo-bar")["foo_bar"].should == false
260
260
  end
261
261
  end
262
262
 
@@ -266,15 +266,15 @@ describe Thor::Options do
266
266
  end
267
267
 
268
268
  it "accepts a switch=<value> assignment" do
269
- parse("--attributes=name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"}
269
+ parse("--attributes=name:string", "age:integer")["attributes"].should == {"name" => "string", "age" => "integer"}
270
270
  end
271
271
 
272
272
  it "accepts a switch <value> assignment" do
273
- parse("--attributes", "name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"}
273
+ parse("--attributes", "name:string", "age:integer")["attributes"].should == {"name" => "string", "age" => "integer"}
274
274
  end
275
275
 
276
276
  it "must not mix values with other switches" do
277
- parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].must == {"name" => "string", "age" => "integer"}
277
+ parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].should == {"name" => "string", "age" => "integer"}
278
278
  end
279
279
  end
280
280
 
@@ -284,15 +284,15 @@ describe Thor::Options do
284
284
  end
285
285
 
286
286
  it "accepts a switch=<value> assignment" do
287
- parse("--attributes=a", "b", "c")["attributes"].must == ["a", "b", "c"]
287
+ parse("--attributes=a", "b", "c")["attributes"].should == ["a", "b", "c"]
288
288
  end
289
289
 
290
290
  it "accepts a switch <value> assignment" do
291
- parse("--attributes", "a", "b", "c")["attributes"].must == ["a", "b", "c"]
291
+ parse("--attributes", "a", "b", "c")["attributes"].should == ["a", "b", "c"]
292
292
  end
293
293
 
294
294
  it "must not mix values with other switches" do
295
- parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].must == ["a", "b", "c"]
295
+ parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].should == ["a", "b", "c"]
296
296
  end
297
297
  end
298
298
 
@@ -302,15 +302,15 @@ describe Thor::Options do
302
302
  end
303
303
 
304
304
  it "accepts a -nXY assignment" do
305
- parse("-n12")["n"].must == 12
305
+ parse("-n12")["n"].should == 12
306
306
  end
307
307
 
308
308
  it "converts values to numeric types" do
309
- parse("-n", "3", "-m", ".5").must == {"n" => 3, "m" => 0.5}
309
+ parse("-n", "3", "-m", ".5").should == {"n" => 3, "m" => 0.5}
310
310
  end
311
311
 
312
312
  it "raises error when value isn't numeric" do
313
- lambda { parse("-n", "foo") }.must raise_error(Thor::MalformattedArgumentError,
313
+ lambda { parse("-n", "foo") }.should raise_error(Thor::MalformattedArgumentError,
314
314
  "Expected numeric value for '-n'; got \"foo\"")
315
315
  end
316
316
  end
@@ -6,7 +6,7 @@ class RakeTask < Rake::TaskLib
6
6
  def initialize
7
7
  define
8
8
  end
9
-
9
+
10
10
  def define
11
11
  desc "Say it's cool"
12
12
  task :cool do
@@ -28,41 +28,41 @@ end
28
28
 
29
29
  describe Thor::RakeCompat do
30
30
  it "sets the rakefile application" do
31
- ["rake_compat_spec.rb", "Thorfile"].must include(Rake.application.rakefile)
31
+ ["rake_compat_spec.rb", "Thorfile"].should include(Rake.application.rakefile)
32
32
  end
33
33
 
34
34
  it "adds rake tasks to thor classes too" do
35
35
  task = ThorTask.tasks["cool"]
36
- task.must be
36
+ task.should be
37
37
  end
38
38
 
39
39
  it "uses rake tasks descriptions on thor" do
40
- ThorTask.tasks["cool"].description.must == "Say it's cool"
40
+ ThorTask.tasks["cool"].description.should == "Say it's cool"
41
41
  end
42
42
 
43
43
  it "gets usage from rake tasks name" do
44
- ThorTask.tasks["cool"].usage.must == "cool"
44
+ ThorTask.tasks["cool"].usage.should == "cool"
45
45
  end
46
46
 
47
47
  it "uses non namespaced name as description if non is available" do
48
- ThorTask::HiperMega.tasks["super"].description.must == "super"
48
+ ThorTask::HiperMega.tasks["super"].description.should == "super"
49
49
  end
50
50
 
51
51
  it "converts namespaces to classes" do
52
- ThorTask.const_get(:HiperMega).must == ThorTask::HiperMega
52
+ ThorTask.const_get(:HiperMega).should == ThorTask::HiperMega
53
53
  end
54
54
 
55
55
  it "does not add tasks from higher namespaces in lowers namespaces" do
56
- ThorTask.tasks["super"].must_not be
56
+ ThorTask.tasks["super"].should_not be
57
57
  end
58
58
 
59
59
  it "invoking the thor task invokes the rake task" do
60
60
  capture(:stdout) do
61
61
  ThorTask.start ["cool"]
62
- end.must == "COOL\n"
62
+ end.should == "COOL\n"
63
63
 
64
64
  capture(:stdout) do
65
65
  ThorTask::HiperMega.start ["super"]
66
- end.must == "HIPER MEGA SUPER\n"
66
+ end.should == "HIPER MEGA SUPER\n"
67
67
  end
68
68
  end
@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class BoringVendorProvidedCLI < Thor
4
+ desc "boring", "do boring stuff"
5
+ def boring
6
+ puts "bored. <yawn>"
7
+ end
8
+ end
9
+
10
+ class ExcitingPluginCLI < Thor
11
+ desc "hooray", "say hooray!"
12
+ def hooray
13
+ puts "hooray!"
14
+ end
15
+
16
+ desc "fireworks", "exciting fireworks!"
17
+ def fireworks
18
+ puts "kaboom!"
19
+ end
20
+ end
21
+
22
+ class SuperSecretPlugin < Thor
23
+ default_task :squirrel
24
+
25
+ desc "squirrel", "All of secret squirrel's secrets"
26
+ def squirrel
27
+ puts "I love nuts"
28
+ end
29
+ end
30
+
31
+ class GroupPlugin < Thor::Group
32
+ desc "part one"
33
+ def part_one
34
+ puts "part one"
35
+ end
36
+
37
+ desc "part two"
38
+ def part_two
39
+ puts "part two"
40
+ end
41
+ end
42
+
43
+
44
+ BoringVendorProvidedCLI.register(
45
+ ExcitingPluginCLI,
46
+ "exciting",
47
+ "do exciting things",
48
+ "Various non-boring actions")
49
+
50
+ BoringVendorProvidedCLI.register(
51
+ SuperSecretPlugin,
52
+ "secret",
53
+ "secret stuff",
54
+ "Nothing to see here. Move along.",
55
+ :hide => true)
56
+
57
+ BoringVendorProvidedCLI.register(
58
+ GroupPlugin,
59
+ 'groupwork',
60
+ "Do a bunch of things in a row",
61
+ "purple monkey dishwasher")
62
+
63
+ describe ".register-ing a Thor subclass" do
64
+ it "registers the plugin as a subcommand" do
65
+ fireworks_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[exciting fireworks]) }
66
+ fireworks_output.should == "kaboom!\n"
67
+ end
68
+
69
+ it "includes the plugin's usage in the help" do
70
+ help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[help]) }
71
+ help_output.should include('do exciting things')
72
+ end
73
+
74
+ context "when hidden" do
75
+ it "omits the hidden plugin's usage from the help" do
76
+ help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[help]) }
77
+ help_output.should_not include('secret stuff')
78
+ end
79
+
80
+ it "registers the plugin as a subcommand" do
81
+ secret_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[secret squirrel]) }
82
+ secret_output.should == "I love nuts\n"
83
+ end
84
+ end
85
+ end
86
+
87
+ describe ".register-ing a Thor::Group subclass" do
88
+ it "registers the group as a single command" do
89
+ group_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[groupwork]) }
90
+ group_output.should == "part one\npart two\n"
91
+ end
92
+ end