vim-jar 0.0.2 → 0.0.3

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.
Files changed (91) hide show
  1. data/Gemfile.lock +4 -1
  2. data/bin/vim-jar +1 -57
  3. data/bundler/ruby/1.8/bin/rake2thor +19 -0
  4. data/bundler/ruby/1.8/bin/thor +19 -0
  5. data/bundler/ruby/1.8/gems/thor-0.14.6/CHANGELOG.rdoc +103 -0
  6. data/bundler/ruby/1.8/gems/thor-0.14.6/LICENSE +20 -0
  7. data/bundler/ruby/1.8/gems/thor-0.14.6/README.md +307 -0
  8. data/bundler/ruby/1.8/gems/thor-0.14.6/Thorfile +24 -0
  9. data/bundler/ruby/1.8/gems/thor-0.14.6/bin/rake2thor +86 -0
  10. data/bundler/ruby/1.8/gems/thor-0.14.6/bin/thor +6 -0
  11. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb +105 -0
  12. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/create_link.rb +57 -0
  13. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/directory.rb +93 -0
  14. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb +134 -0
  15. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb +270 -0
  16. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/inject_into_file.rb +109 -0
  17. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions.rb +314 -0
  18. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/base.rb +579 -0
  19. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/file_binary_read.rb +9 -0
  20. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  21. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/ordered_hash.rb +100 -0
  22. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/error.rb +30 -0
  23. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/group.rb +273 -0
  24. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/invocation.rb +168 -0
  25. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/argument.rb +67 -0
  26. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/arguments.rb +161 -0
  27. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/option.rb +120 -0
  28. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/options.rb +173 -0
  29. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser.rb +4 -0
  30. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/rake_compat.rb +66 -0
  31. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/runner.rb +309 -0
  32. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/basic.rb +290 -0
  33. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/color.rb +108 -0
  34. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/html.rb +121 -0
  35. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell.rb +88 -0
  36. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/task.rb +114 -0
  37. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/util.rb +229 -0
  38. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/version.rb +3 -0
  39. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor.rb +334 -0
  40. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/create_file_spec.rb +170 -0
  41. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/directory_spec.rb +136 -0
  42. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/empty_directory_spec.rb +98 -0
  43. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/file_manipulation_spec.rb +310 -0
  44. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/inject_into_file_spec.rb +135 -0
  45. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions_spec.rb +322 -0
  46. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/base_spec.rb +269 -0
  47. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  48. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/core_ext/ordered_hash_spec.rb +115 -0
  49. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/application.rb +2 -0
  50. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/bundle/execute.rb +6 -0
  51. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/bundle/main.thor +1 -0
  52. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  53. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/README +3 -0
  54. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/block_helper.rb +3 -0
  55. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/components/.empty_directory +0 -0
  56. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/config.rb +1 -0
  57. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/group.thor +114 -0
  58. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/invoke.thor +112 -0
  59. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/path with spaces +0 -0
  60. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/script.thor +184 -0
  61. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/task.thor +10 -0
  62. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/group_spec.rb +178 -0
  63. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/invocation_spec.rb +100 -0
  64. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/argument_spec.rb +47 -0
  65. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/arguments_spec.rb +64 -0
  66. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/option_spec.rb +202 -0
  67. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/options_spec.rb +319 -0
  68. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/rake_compat_spec.rb +68 -0
  69. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/register_spec.rb +92 -0
  70. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/runner_spec.rb +210 -0
  71. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/basic_spec.rb +223 -0
  72. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/color_spec.rb +41 -0
  73. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/html_spec.rb +27 -0
  74. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell_spec.rb +47 -0
  75. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/spec_helper.rb +54 -0
  76. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/task_spec.rb +69 -0
  77. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/thor_spec.rb +334 -0
  78. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/util_spec.rb +163 -0
  79. data/bundler/ruby/1.8/specifications/thor-0.14.6.gemspec +48 -0
  80. data/lib/vim-jar/cli.rb +84 -67
  81. data/lib/vim-jar/config.rb +9 -0
  82. data/lib/vim-jar/installer/git.rb +8 -7
  83. data/lib/vim-jar/plugin.rb +61 -18
  84. data/lib/vim-jar/version.rb +1 -1
  85. data/lib/vim-jar.rb +1 -0
  86. data/spec/vim-jar/config_spec.rb +17 -0
  87. data/spec/vim-jar/git-config +16 -0
  88. data/spec/vim-jar/gitmodules +6 -0
  89. data/spec/vim-jar/plugin_spec.rb +46 -0
  90. data/vim-jar.gemspec +1 -0
  91. metadata +104 -9
@@ -0,0 +1,319 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'thor/parser'
3
+
4
+ describe Thor::Options do
5
+ def create(opts, defaults={})
6
+ opts.each do |key, value|
7
+ opts[key] = Thor::Option.parse(key, value) unless value.is_a?(Thor::Option)
8
+ end
9
+
10
+ @opt = Thor::Options.new(opts, defaults)
11
+ end
12
+
13
+ def parse(*args)
14
+ @opt.parse(args.flatten)
15
+ end
16
+
17
+ def check_unknown!
18
+ @opt.check_unknown!
19
+ end
20
+
21
+ describe "#to_switches" do
22
+ it "turns true values into a flag" do
23
+ Thor::Options.to_switches(:color => true).should == "--color"
24
+ end
25
+
26
+ it "ignores nil" do
27
+ Thor::Options.to_switches(:color => nil).should == ""
28
+ end
29
+
30
+ it "ignores false" do
31
+ Thor::Options.to_switches(:color => false).should == ""
32
+ end
33
+
34
+ it "writes --name value for anything else" do
35
+ Thor::Options.to_switches(:format => "specdoc").should == '--format "specdoc"'
36
+ end
37
+
38
+ it "joins several values" do
39
+ switches = Thor::Options.to_switches(:color => true, :foo => "bar").split(' ').sort
40
+ switches.should == ['"bar"', "--color", "--foo"]
41
+ end
42
+
43
+ it "accepts arrays" do
44
+ Thor::Options.to_switches(:count => [1,2,3]).should == "--count 1 2 3"
45
+ end
46
+
47
+ it "accepts hashes" do
48
+ Thor::Options.to_switches(:count => {:a => :b}).should == "--count a:b"
49
+ end
50
+
51
+ it "accepts underscored options" do
52
+ Thor::Options.to_switches(:under_score_option => "foo bar").should == '--under_score_option "foo bar"'
53
+ end
54
+
55
+ end
56
+
57
+ describe "#parse" do
58
+ it "allows multiple aliases for a given switch" do
59
+ create ["--foo", "--bar", "--baz"] => :string
60
+ parse("--foo", "12")["foo"].should == "12"
61
+ parse("--bar", "12")["foo"].should == "12"
62
+ parse("--baz", "12")["foo"].should == "12"
63
+ end
64
+
65
+ it "allows custom short names" do
66
+ create "-f" => :string
67
+ parse("-f", "12").should == {"f" => "12"}
68
+ end
69
+
70
+ it "allows custom short-name aliases" do
71
+ create ["--bar", "-f"] => :string
72
+ parse("-f", "12").should == {"bar" => "12"}
73
+ end
74
+
75
+ it "accepts conjoined short switches" do
76
+ create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => true
77
+ opts = parse("-fba")
78
+ opts["foo"].should be_true
79
+ opts["bar"].should be_true
80
+ opts["app"].should be_true
81
+ end
82
+
83
+ it "accepts conjoined short switches with input" do
84
+ create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => :required
85
+ opts = parse "-fba", "12"
86
+ opts["foo"].should be_true
87
+ opts["bar"].should be_true
88
+ opts["app"].should == "12"
89
+ end
90
+
91
+ it "returns the default value if none is provided" do
92
+ create :foo => "baz", :bar => :required
93
+ parse("--bar", "boom")["foo"].should == "baz"
94
+ end
95
+
96
+ it "returns the default value from defaults hash to required arguments" do
97
+ create Hash[:bar => :required], Hash[:bar => "baz"]
98
+ parse["bar"].should == "baz"
99
+ end
100
+
101
+ it "gives higher priority to defaults given in the hash" do
102
+ create Hash[:bar => true], Hash[:bar => false]
103
+ parse["bar"].should == false
104
+ end
105
+
106
+ it "raises an error for unknown switches" do
107
+ create :foo => "baz", :bar => :required
108
+ parse("--bar", "baz", "--baz", "unknown")
109
+ lambda { check_unknown! }.should raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'")
110
+ end
111
+
112
+ it "skips leading non-switches" do
113
+ create(:foo => "baz")
114
+
115
+ parse("asdf", "--foo", "bar").should == {"foo" => "bar"}
116
+ end
117
+
118
+ it "correctly recognizes things that look kind of like options, but aren't, as not options" do
119
+ create(:foo => "baz")
120
+ parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").should == {"foo" => "--asdf---dsf--asdf"}
121
+ check_unknown!
122
+ end
123
+
124
+ it "excepts underscores in commandline args hash for boolean" do
125
+ create :foo_bar => :boolean
126
+ parse("--foo_bar")["foo_bar"].should == true
127
+ parse("--no_foo_bar")["foo_bar"].should == false
128
+ end
129
+
130
+ it "excepts underscores in commandline args hash for strings" do
131
+ create :foo_bar => :string, :baz_foo => :string
132
+ parse("--foo_bar", "baz")["foo_bar"].should == "baz"
133
+ parse("--baz_foo", "foo bar")["baz_foo"].should == "foo bar"
134
+ end
135
+
136
+ describe "with no input" do
137
+ it "and no switches returns an empty hash" do
138
+ create({})
139
+ parse.should == {}
140
+ end
141
+
142
+ it "and several switches returns an empty hash" do
143
+ create "--foo" => :boolean, "--bar" => :string
144
+ parse.should == {}
145
+ end
146
+
147
+ it "and a required switch raises an error" do
148
+ create "--foo" => :required
149
+ lambda { parse }.should raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'")
150
+ end
151
+ end
152
+
153
+ describe "with one required and one optional switch" do
154
+ before :each do
155
+ create "--foo" => :required, "--bar" => :boolean
156
+ end
157
+
158
+ it "raises an error if the required switch has no argument" do
159
+ lambda { parse("--foo") }.should raise_error(Thor::MalformattedArgumentError)
160
+ end
161
+
162
+ it "raises an error if the required switch isn't given" do
163
+ lambda { parse("--bar") }.should raise_error(Thor::RequiredArgumentMissingError)
164
+ end
165
+
166
+ it "raises an error if the required switch is set to nil" do
167
+ lambda { parse("--no-foo") }.should raise_error(Thor::RequiredArgumentMissingError)
168
+ end
169
+
170
+ it "does not raises an error if the required option has a default value" do
171
+ create :foo => Thor::Option.new("foo", nil, true, :string, "baz"), :bar => :boolean
172
+ lambda { parse("--bar") }.should_not raise_error
173
+ end
174
+ end
175
+
176
+ describe "with :string type" do
177
+ before(:each) do
178
+ create ["--foo", "-f"] => :required
179
+ end
180
+
181
+ it "accepts a switch <value> assignment" do
182
+ parse("--foo", "12")["foo"].should == "12"
183
+ end
184
+
185
+ it "accepts a switch=<value> assignment" do
186
+ parse("-f=12")["foo"].should == "12"
187
+ parse("--foo=12")["foo"].should == "12"
188
+ parse("--foo=bar=baz")["foo"].should == "bar=baz"
189
+ end
190
+
191
+ it "must accept underscores switch=value assignment" do
192
+ create :foo_bar => :required
193
+ parse("--foo_bar=http://example.com/under_score/")["foo_bar"].should == "http://example.com/under_score/"
194
+ end
195
+
196
+ it "accepts a --no-switch format" do
197
+ create "--foo" => "bar"
198
+ parse("--no-foo")["foo"].should be_nil
199
+ end
200
+
201
+ it "does not consume an argument for --no-switch format" do
202
+ create "--cheese" => :string
203
+ parse('burger', '--no-cheese', 'fries')["cheese"].should be_nil
204
+ end
205
+
206
+ it "accepts a --switch format on non required types" do
207
+ create "--foo" => :string
208
+ parse("--foo")["foo"].should == "foo"
209
+ end
210
+
211
+ it "accepts a --switch format on non required types with default values" do
212
+ create "--baz" => :string, "--foo" => "bar"
213
+ parse("--baz", "bang", "--foo")["foo"].should == "bar"
214
+ end
215
+
216
+ it "overwrites earlier values with later values" do
217
+ parse("--foo=bar", "--foo", "12")["foo"].should == "12"
218
+ parse("--foo", "12", "--foo", "13")["foo"].should == "13"
219
+ end
220
+ end
221
+
222
+ describe "with :boolean type" do
223
+ before(:each) do
224
+ create "--foo" => false
225
+ end
226
+
227
+ it "accepts --opt assignment" do
228
+ parse("--foo")["foo"].should == true
229
+ parse("--foo", "--bar")["foo"].should == true
230
+ end
231
+
232
+ it "accepts --opt=value assignment" do
233
+ parse("--foo=true")["foo"].should == true
234
+ parse("--foo=false")["foo"].should == false
235
+ end
236
+
237
+ it "accepts --[no-]opt variant, setting false for value" do
238
+ parse("--no-foo")["foo"].should == false
239
+ end
240
+
241
+ it "accepts --[skip-]opt variant, setting false for value" do
242
+ parse("--skip-foo")["foo"].should == false
243
+ end
244
+
245
+ it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do
246
+ create "--no-foo" => true
247
+ parse("--no-foo")["no-foo"].should == true
248
+ end
249
+
250
+ it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do
251
+ create "--skip-foo" => true
252
+ parse("--skip-foo")["skip-foo"].should == true
253
+ end
254
+
255
+ it "accepts inputs in the human name format" do
256
+ create :foo_bar => :boolean
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
+ end
261
+ end
262
+
263
+ describe "with :hash type" do
264
+ before(:each) do
265
+ create "--attributes" => :hash
266
+ end
267
+
268
+ it "accepts a switch=<value> assignment" do
269
+ parse("--attributes=name:string", "age:integer")["attributes"].should == {"name" => "string", "age" => "integer"}
270
+ end
271
+
272
+ it "accepts a switch <value> assignment" do
273
+ parse("--attributes", "name:string", "age:integer")["attributes"].should == {"name" => "string", "age" => "integer"}
274
+ end
275
+
276
+ it "must not mix values with other switches" do
277
+ parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].should == {"name" => "string", "age" => "integer"}
278
+ end
279
+ end
280
+
281
+ describe "with :array type" do
282
+ before(:each) do
283
+ create "--attributes" => :array
284
+ end
285
+
286
+ it "accepts a switch=<value> assignment" do
287
+ parse("--attributes=a", "b", "c")["attributes"].should == ["a", "b", "c"]
288
+ end
289
+
290
+ it "accepts a switch <value> assignment" do
291
+ parse("--attributes", "a", "b", "c")["attributes"].should == ["a", "b", "c"]
292
+ end
293
+
294
+ it "must not mix values with other switches" do
295
+ parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].should == ["a", "b", "c"]
296
+ end
297
+ end
298
+
299
+ describe "with :numeric type" do
300
+ before(:each) do
301
+ create "n" => :numeric, "m" => 5
302
+ end
303
+
304
+ it "accepts a -nXY assignment" do
305
+ parse("-n12")["n"].should == 12
306
+ end
307
+
308
+ it "converts values to numeric types" do
309
+ parse("-n", "3", "-m", ".5").should == {"n" => 3, "m" => 0.5}
310
+ end
311
+
312
+ it "raises error when value isn't numeric" do
313
+ lambda { parse("-n", "foo") }.should raise_error(Thor::MalformattedArgumentError,
314
+ "Expected numeric value for '-n'; got \"foo\"")
315
+ end
316
+ end
317
+
318
+ end
319
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'thor/rake_compat'
3
+ require 'rake/tasklib'
4
+
5
+ class RakeTask < Rake::TaskLib
6
+ def initialize
7
+ define
8
+ end
9
+
10
+ def define
11
+ desc "Say it's cool"
12
+ task :cool do
13
+ puts "COOL"
14
+ end
15
+
16
+ namespace :hiper_mega do
17
+ task :super do
18
+ puts "HIPER MEGA SUPER"
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ class ThorTask < Thor
25
+ include Thor::RakeCompat
26
+ RakeTask.new
27
+ end
28
+
29
+ describe Thor::RakeCompat do
30
+ it "sets the rakefile application" do
31
+ ["rake_compat_spec.rb", "Thorfile"].should include(Rake.application.rakefile)
32
+ end
33
+
34
+ it "adds rake tasks to thor classes too" do
35
+ task = ThorTask.tasks["cool"]
36
+ task.should be
37
+ end
38
+
39
+ it "uses rake tasks descriptions on thor" do
40
+ ThorTask.tasks["cool"].description.should == "Say it's cool"
41
+ end
42
+
43
+ it "gets usage from rake tasks name" do
44
+ ThorTask.tasks["cool"].usage.should == "cool"
45
+ end
46
+
47
+ it "uses non namespaced name as description if non is available" do
48
+ ThorTask::HiperMega.tasks["super"].description.should == "super"
49
+ end
50
+
51
+ it "converts namespaces to classes" do
52
+ ThorTask.const_get(:HiperMega).should == ThorTask::HiperMega
53
+ end
54
+
55
+ it "does not add tasks from higher namespaces in lowers namespaces" do
56
+ ThorTask.tasks["super"].should_not be
57
+ end
58
+
59
+ it "invoking the thor task invokes the rake task" do
60
+ capture(:stdout) do
61
+ ThorTask.start ["cool"]
62
+ end.should == "COOL\n"
63
+
64
+ capture(:stdout) do
65
+ ThorTask::HiperMega.start ["super"]
66
+ end.should == "HIPER MEGA SUPER\n"
67
+ end
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
@@ -0,0 +1,210 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+ require 'thor/runner'
3
+
4
+ describe Thor::Runner do
5
+ describe "#help" do
6
+ it "shows information about Thor::Runner itself" do
7
+ capture(:stdout){ Thor::Runner.start(["help"]) }.should =~ /List the available thor tasks/
8
+ end
9
+
10
+ it "shows information about an specific Thor::Runner task" do
11
+ content = capture(:stdout){ Thor::Runner.start(["help", "list"]) }
12
+ content.should =~ /List the available thor tasks/
13
+ content.should_not =~ /help \[TASK\]/
14
+ end
15
+
16
+ it "shows information about a specific Thor class" do
17
+ content = capture(:stdout){ Thor::Runner.start(["help", "my_script"]) }
18
+ content.should =~ /zoo\s+# zoo around/m
19
+ end
20
+
21
+ it "shows information about an specific task from an specific Thor class" do
22
+ content = capture(:stdout){ Thor::Runner.start(["help", "my_script:zoo"]) }
23
+ content.should =~ /zoo around/
24
+ content.should_not =~ /help \[TASK\]/
25
+ end
26
+
27
+ it "shows information about a specific Thor group class" do
28
+ content = capture(:stdout){ Thor::Runner.start(["help", "my_counter"]) }
29
+ content.should =~ /my_counter N/
30
+ end
31
+
32
+ it "raises error if a class/task cannot be found" do
33
+ content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) }
34
+ content.strip.should == 'Could not find task "unknown" in "default" namespace.'
35
+ end
36
+ end
37
+
38
+ describe "#start" do
39
+ it "invokes a task from Thor::Runner" do
40
+ ARGV.replace ["list"]
41
+ capture(:stdout){ Thor::Runner.start }.should =~ /my_counter N/
42
+ end
43
+
44
+ it "invokes a task from a specific Thor class" do
45
+ ARGV.replace ["my_script:zoo"]
46
+ Thor::Runner.start.should be_true
47
+ end
48
+
49
+ it "invokes the default task from a specific Thor class if none is specified" do
50
+ ARGV.replace ["my_script"]
51
+ Thor::Runner.start.should == "default task"
52
+ end
53
+
54
+ it "forwads arguments to the invoked task" do
55
+ ARGV.replace ["my_script:animal", "horse"]
56
+ Thor::Runner.start.should == ["horse"]
57
+ end
58
+
59
+ it "invokes tasks through shortcuts" do
60
+ ARGV.replace ["my_script", "-T", "horse"]
61
+ Thor::Runner.start.should == ["horse"]
62
+ end
63
+
64
+ it "invokes a Thor::Group" do
65
+ ARGV.replace ["my_counter", "1", "2", "--third", "3"]
66
+ Thor::Runner.start.should == [1, 2, 3]
67
+ end
68
+
69
+ it "raises an error if class/task can't be found" do
70
+ ARGV.replace ["unknown"]
71
+ content = capture(:stderr){ Thor::Runner.start }
72
+ content.strip.should == 'Could not find task "unknown" in "default" namespace.'
73
+ end
74
+
75
+ it "does not swallow NoMethodErrors that occur inside the called method" do
76
+ ARGV.replace ["my_script:call_unexistent_method"]
77
+ lambda { Thor::Runner.start }.should raise_error(NoMethodError)
78
+ end
79
+
80
+ it "does not swallow Thor::Group InvocationError" do
81
+ ARGV.replace ["whiny_generator"]
82
+ lambda { Thor::Runner.start }.should raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/)
83
+ end
84
+
85
+ it "does not swallow Thor InvocationError" do
86
+ ARGV.replace ["my_script:animal"]
87
+ content = capture(:stderr) { Thor::Runner.start }
88
+ content.strip.should == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".'
89
+ end
90
+ end
91
+
92
+ describe "tasks" do
93
+ before(:each) do
94
+ @location = "#{File.dirname(__FILE__)}/fixtures/task.thor"
95
+ @original_yaml = {
96
+ "random" => {
97
+ :location => @location,
98
+ :filename => "4a33b894ffce85d7b412fc1b36f88fe0",
99
+ :namespaces => ["amazing"]
100
+ }
101
+ }
102
+
103
+ root_file = File.join(Thor::Util.thor_root, "thor.yml")
104
+
105
+ # Stub load and save to avoid thor.yaml from being overwritten
106
+ YAML.stub!(:load_file).and_return(@original_yaml)
107
+ File.stub!(:exists?).with(root_file).and_return(true)
108
+ File.stub!(:open).with(root_file, "w")
109
+ end
110
+
111
+ describe "list" do
112
+ it "gives a list of the available tasks" do
113
+ ARGV.replace ["list"]
114
+ content = capture(:stdout) { Thor::Runner.start }
115
+ content.should =~ /amazing:describe NAME\s+# say that someone is amazing/m
116
+ end
117
+
118
+ it "gives a list of the available Thor::Group classes" do
119
+ ARGV.replace ["list"]
120
+ capture(:stdout) { Thor::Runner.start }.should =~ /my_counter N/
121
+ end
122
+
123
+ it "can filter a list of the available tasks by --group" do
124
+ ARGV.replace ["list", "--group", "standard"]
125
+ capture(:stdout) { Thor::Runner.start }.should =~ /amazing:describe NAME/
126
+ ARGV.replace []
127
+ capture(:stdout) { Thor::Runner.start }.should_not =~ /my_script:animal TYPE/
128
+ ARGV.replace ["list", "--group", "script"]
129
+ capture(:stdout) { Thor::Runner.start }.should =~ /my_script:animal TYPE/
130
+ end
131
+
132
+ it "can skip all filters to show all tasks using --all" do
133
+ ARGV.replace ["list", "--all"]
134
+ content = capture(:stdout) { Thor::Runner.start }
135
+ content.should =~ /amazing:describe NAME/
136
+ content.should =~ /my_script:animal TYPE/
137
+ end
138
+
139
+ it "doesn't list superclass tasks in the subclass" do
140
+ ARGV.replace ["list"]
141
+ capture(:stdout) { Thor::Runner.start }.should_not =~ /amazing:help/
142
+ end
143
+
144
+ it "presents tasks in the default namespace with an empty namespace" do
145
+ ARGV.replace ["list"]
146
+ capture(:stdout) { Thor::Runner.start }.should =~ /^thor :cow\s+# prints 'moo'/m
147
+ end
148
+
149
+ it "runs tasks with an empty namespace from the default namespace" do
150
+ ARGV.replace [":task_conflict"]
151
+ capture(:stdout) { Thor::Runner.start }.should == "task\n"
152
+ end
153
+
154
+ it "runs groups even when there is a task with the same name" do
155
+ ARGV.replace ["task_conflict"]
156
+ capture(:stdout) { Thor::Runner.start }.should == "group\n"
157
+ end
158
+
159
+ it "runs tasks with no colon in the default namespace" do
160
+ ARGV.replace ["cow"]
161
+ capture(:stdout) { Thor::Runner.start }.should == "moo\n"
162
+ end
163
+ end
164
+
165
+ describe "uninstall" do
166
+ before(:each) do
167
+ path = File.join(Thor::Util.thor_root, @original_yaml["random"][:filename])
168
+ FileUtils.should_receive(:rm_rf).with(path)
169
+ end
170
+
171
+ it "uninstalls existing thor modules" do
172
+ silence(:stdout) { Thor::Runner.start(["uninstall", "random"]) }
173
+ end
174
+ end
175
+
176
+ describe "installed" do
177
+ before(:each) do
178
+ Dir.should_receive(:[]).and_return([])
179
+ end
180
+
181
+ it "displays the modules installed in a pretty way" do
182
+ stdout = capture(:stdout) { Thor::Runner.start(["installed"]) }
183
+ stdout.should =~ /random\s*amazing/
184
+ stdout.should =~ /amazing:describe NAME\s+# say that someone is amazing/m
185
+ end
186
+ end
187
+
188
+ describe "install/update" do
189
+ before(:each) do
190
+ FileUtils.stub!(:mkdir_p)
191
+ FileUtils.stub!(:touch)
192
+ $stdin.stub!(:gets).and_return("Y")
193
+
194
+ path = File.join(Thor::Util.thor_root, Digest::MD5.hexdigest(@location + "random"))
195
+ File.should_receive(:open).with(path, "w")
196
+ end
197
+
198
+ it "updates existing thor files" do
199
+ path = File.join(Thor::Util.thor_root, @original_yaml["random"][:filename])
200
+ File.should_receive(:delete).with(path)
201
+ silence(:stdout) { Thor::Runner.start(["update", "random"]) }
202
+ end
203
+
204
+ it "installs thor files" do
205
+ ARGV.replace ["install", @location]
206
+ silence(:stdout) { Thor::Runner.start }
207
+ end
208
+ end
209
+ end
210
+ end