angry_mob 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +123 -0
  3. data/bin/mob +139 -0
  4. data/lib/angry_mob.rb +28 -0
  5. data/lib/angry_mob/act.rb +111 -0
  6. data/lib/angry_mob/act/scheduler.rb +143 -0
  7. data/lib/angry_mob/action.rb +11 -0
  8. data/lib/angry_mob/builder.rb +115 -0
  9. data/lib/angry_mob/extend.rb +10 -0
  10. data/lib/angry_mob/extend/array.rb +30 -0
  11. data/lib/angry_mob/extend/blank.rb +108 -0
  12. data/lib/angry_mob/extend/blankslate.rb +109 -0
  13. data/lib/angry_mob/extend/dictionary.rb +140 -0
  14. data/lib/angry_mob/extend/hash.rb +67 -0
  15. data/lib/angry_mob/extend/object.rb +21 -0
  16. data/lib/angry_mob/extend/pathname.rb +23 -0
  17. data/lib/angry_mob/extend/string.rb +8 -0
  18. data/lib/angry_mob/log.rb +28 -0
  19. data/lib/angry_mob/mob.rb +77 -0
  20. data/lib/angry_mob/mob_loader.rb +115 -0
  21. data/lib/angry_mob/node.rb +44 -0
  22. data/lib/angry_mob/notifier.rb +76 -0
  23. data/lib/angry_mob/target.rb +257 -0
  24. data/lib/angry_mob/target/arguments.rb +71 -0
  25. data/lib/angry_mob/target/call.rb +57 -0
  26. data/lib/angry_mob/target/default_resource_locator.rb +11 -0
  27. data/lib/angry_mob/target/defaults.rb +23 -0
  28. data/lib/angry_mob/target/mother.rb +66 -0
  29. data/lib/angry_mob/target/notify.rb +57 -0
  30. data/lib/angry_mob/target/tracking.rb +96 -0
  31. data/lib/angry_mob/ui.rb +247 -0
  32. data/lib/angry_mob/util.rb +11 -0
  33. data/lib/angry_mob/vendored.rb +8 -0
  34. data/lib/angry_mob/version.rb +3 -0
  35. data/vendor/angry_hash/Rakefile +17 -0
  36. data/vendor/angry_hash/VERSION +1 -0
  37. data/vendor/angry_hash/angry_hash.gemspec +47 -0
  38. data/vendor/angry_hash/examples/accessors_eg.rb +46 -0
  39. data/vendor/angry_hash/examples/creation_eg.rb +43 -0
  40. data/vendor/angry_hash/examples/dsl.eg.rb +18 -0
  41. data/vendor/angry_hash/examples/dup_eg.rb +86 -0
  42. data/vendor/angry_hash/examples/eg_helper.rb +24 -0
  43. data/vendor/angry_hash/examples/merge_eg.rb +135 -0
  44. data/vendor/angry_hash/lib/angry_hash.rb +215 -0
  45. data/vendor/angry_hash/lib/angry_hash/dsl.rb +44 -0
  46. data/vendor/angry_hash/lib/angry_hash/extension_tracking.rb +12 -0
  47. data/vendor/angry_hash/lib/angry_hash/merge_string.rb +58 -0
  48. data/vendor/json/COPYING +58 -0
  49. data/vendor/json/GPL +340 -0
  50. data/vendor/json/README +360 -0
  51. data/vendor/json/lib/json/common.rb +371 -0
  52. data/vendor/json/lib/json/pure.rb +77 -0
  53. data/vendor/json/lib/json/pure/generator.rb +443 -0
  54. data/vendor/json/lib/json/pure/parser.rb +303 -0
  55. data/vendor/json/lib/json/version.rb +8 -0
  56. data/vendor/thor/CHANGELOG.rdoc +89 -0
  57. data/vendor/thor/LICENSE +20 -0
  58. data/vendor/thor/README.rdoc +297 -0
  59. data/vendor/thor/Thorfile +69 -0
  60. data/vendor/thor/bin/rake2thor +86 -0
  61. data/vendor/thor/bin/thor +6 -0
  62. data/vendor/thor/lib/thor.rb +244 -0
  63. data/vendor/thor/lib/thor/actions.rb +275 -0
  64. data/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  65. data/vendor/thor/lib/thor/actions/directory.rb +91 -0
  66. data/vendor/thor/lib/thor/actions/empty_directory.rb +134 -0
  67. data/vendor/thor/lib/thor/actions/file_manipulation.rb +223 -0
  68. data/vendor/thor/lib/thor/actions/inject_into_file.rb +104 -0
  69. data/vendor/thor/lib/thor/base.rb +540 -0
  70. data/vendor/thor/lib/thor/core_ext/file_binary_read.rb +9 -0
  71. data/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  72. data/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  73. data/vendor/thor/lib/thor/error.rb +30 -0
  74. data/vendor/thor/lib/thor/group.rb +271 -0
  75. data/vendor/thor/lib/thor/invocation.rb +180 -0
  76. data/vendor/thor/lib/thor/parser.rb +4 -0
  77. data/vendor/thor/lib/thor/parser/argument.rb +67 -0
  78. data/vendor/thor/lib/thor/parser/arguments.rb +150 -0
  79. data/vendor/thor/lib/thor/parser/option.rb +128 -0
  80. data/vendor/thor/lib/thor/parser/options.rb +169 -0
  81. data/vendor/thor/lib/thor/rake_compat.rb +66 -0
  82. data/vendor/thor/lib/thor/runner.rb +314 -0
  83. data/vendor/thor/lib/thor/shell.rb +83 -0
  84. data/vendor/thor/lib/thor/shell/basic.rb +239 -0
  85. data/vendor/thor/lib/thor/shell/color.rb +108 -0
  86. data/vendor/thor/lib/thor/task.rb +102 -0
  87. data/vendor/thor/lib/thor/util.rb +224 -0
  88. data/vendor/thor/lib/thor/version.rb +3 -0
  89. data/vendor/thor/spec/actions/create_file_spec.rb +170 -0
  90. data/vendor/thor/spec/actions/directory_spec.rb +131 -0
  91. data/vendor/thor/spec/actions/empty_directory_spec.rb +91 -0
  92. data/vendor/thor/spec/actions/file_manipulation_spec.rb +271 -0
  93. data/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
  94. data/vendor/thor/spec/actions_spec.rb +292 -0
  95. data/vendor/thor/spec/base_spec.rb +263 -0
  96. data/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  97. data/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
  98. data/vendor/thor/spec/fixtures/application.rb +2 -0
  99. data/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
  100. data/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
  101. data/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  102. data/vendor/thor/spec/fixtures/doc/README +3 -0
  103. data/vendor/thor/spec/fixtures/doc/config.rb +1 -0
  104. data/vendor/thor/spec/fixtures/group.thor +90 -0
  105. data/vendor/thor/spec/fixtures/invoke.thor +112 -0
  106. data/vendor/thor/spec/fixtures/script.thor +145 -0
  107. data/vendor/thor/spec/fixtures/task.thor +10 -0
  108. data/vendor/thor/spec/group_spec.rb +171 -0
  109. data/vendor/thor/spec/invocation_spec.rb +107 -0
  110. data/vendor/thor/spec/parser/argument_spec.rb +47 -0
  111. data/vendor/thor/spec/parser/arguments_spec.rb +64 -0
  112. data/vendor/thor/spec/parser/option_spec.rb +202 -0
  113. data/vendor/thor/spec/parser/options_spec.rb +292 -0
  114. data/vendor/thor/spec/rake_compat_spec.rb +68 -0
  115. data/vendor/thor/spec/runner_spec.rb +210 -0
  116. data/vendor/thor/spec/shell/basic_spec.rb +205 -0
  117. data/vendor/thor/spec/shell/color_spec.rb +41 -0
  118. data/vendor/thor/spec/shell_spec.rb +34 -0
  119. data/vendor/thor/spec/spec.opts +1 -0
  120. data/vendor/thor/spec/spec_helper.rb +54 -0
  121. data/vendor/thor/spec/task_spec.rb +69 -0
  122. data/vendor/thor/spec/thor_spec.rb +237 -0
  123. data/vendor/thor/spec/util_spec.rb +163 -0
  124. data/vendor/thor/thor.gemspec +120 -0
  125. metadata +199 -0
@@ -0,0 +1,292 @@
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).must == "--color"
24
+ end
25
+
26
+ it "ignores nil" do
27
+ Thor::Options.to_switches(:color => nil).must == ""
28
+ end
29
+
30
+ it "ignores false" do
31
+ Thor::Options.to_switches(:color => false).must == ""
32
+ end
33
+
34
+ it "writes --name value for anything else" do
35
+ Thor::Options.to_switches(:format => "specdoc").must == '--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.must == ['"bar"', "--color", "--foo"]
41
+ end
42
+
43
+ it "accepts arrays" do
44
+ Thor::Options.to_switches(:count => [1,2,3]).must == "--count 1 2 3"
45
+ end
46
+
47
+ it "accepts hashes" do
48
+ Thor::Options.to_switches(:count => {:a => :b}).must == "--count a:b"
49
+ end
50
+ end
51
+
52
+ describe "#parse" do
53
+ it "allows multiple aliases for a given switch" do
54
+ create ["--foo", "--bar", "--baz"] => :string
55
+ parse("--foo", "12")["foo"].must == "12"
56
+ parse("--bar", "12")["foo"].must == "12"
57
+ parse("--baz", "12")["foo"].must == "12"
58
+ end
59
+
60
+ it "allows custom short names" do
61
+ create "-f" => :string
62
+ parse("-f", "12").must == {"f" => "12"}
63
+ end
64
+
65
+ it "allows custom short-name aliases" do
66
+ create ["--bar", "-f"] => :string
67
+ parse("-f", "12").must == {"bar" => "12"}
68
+ end
69
+
70
+ it "accepts conjoined short switches" do
71
+ create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => true
72
+ opts = parse("-fba")
73
+ opts["foo"].must be_true
74
+ opts["bar"].must be_true
75
+ opts["app"].must be_true
76
+ end
77
+
78
+ it "accepts conjoined short switches with input" do
79
+ create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => :required
80
+ opts = parse "-fba", "12"
81
+ opts["foo"].must be_true
82
+ opts["bar"].must be_true
83
+ opts["app"].must == "12"
84
+ end
85
+
86
+ it "returns the default value if none is provided" do
87
+ create :foo => "baz", :bar => :required
88
+ parse("--bar", "boom")["foo"].must == "baz"
89
+ end
90
+
91
+ it "returns the default value from defaults hash to required arguments" do
92
+ create Hash[:bar => :required], Hash[:bar => "baz"]
93
+ parse["bar"].must == "baz"
94
+ end
95
+
96
+ it "gives higher priority to defaults given in the hash" do
97
+ create Hash[:bar => true], Hash[:bar => false]
98
+ parse["bar"].must == false
99
+ end
100
+
101
+ it "raises an error for unknown switches" do
102
+ create :foo => "baz", :bar => :required
103
+ parse("--bar", "baz", "--baz", "unknown")
104
+ lambda { check_unknown! }.must raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'")
105
+ end
106
+
107
+ it "skips leading non-switches" do
108
+ create(:foo => "baz")
109
+
110
+ parse("asdf", "--foo", "bar").must == {"foo" => "bar"}
111
+ end
112
+
113
+ it "correctly recognizes things that look kind of like options, but aren't, as not options" do
114
+ create(:foo => "baz")
115
+ parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").must == {"foo" => "--asdf---dsf--asdf"}
116
+ check_unknown!
117
+ end
118
+
119
+ describe "with no input" do
120
+ it "and no switches returns an empty hash" do
121
+ create({})
122
+ parse.must == {}
123
+ end
124
+
125
+ it "and several switches returns an empty hash" do
126
+ create "--foo" => :boolean, "--bar" => :string
127
+ parse.must == {}
128
+ end
129
+
130
+ it "and a required switch raises an error" do
131
+ create "--foo" => :required
132
+ lambda { parse }.must raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'")
133
+ end
134
+ end
135
+
136
+ describe "with one required and one optional switch" do
137
+ before :each do
138
+ create "--foo" => :required, "--bar" => :boolean
139
+ end
140
+
141
+ it "raises an error if the required switch has no argument" do
142
+ lambda { parse("--foo") }.must raise_error(Thor::MalformattedArgumentError)
143
+ end
144
+
145
+ it "raises an error if the required switch isn't given" do
146
+ lambda { parse("--bar") }.must raise_error(Thor::RequiredArgumentMissingError)
147
+ end
148
+
149
+ it "raises an error if the required switch is set to nil" do
150
+ lambda { parse("--no-foo") }.must raise_error(Thor::RequiredArgumentMissingError)
151
+ end
152
+
153
+ it "does not raises an error if the required option has a default value" do
154
+ create :foo => Thor::Option.new("foo", nil, true, :string, "baz"), :bar => :boolean
155
+ lambda { parse("--bar") }.must_not raise_error
156
+ end
157
+ end
158
+
159
+ describe "with :string type" do
160
+ before(:each) do
161
+ create ["--foo", "-f"] => :required
162
+ end
163
+
164
+ it "accepts a switch <value> assignment" do
165
+ parse("--foo", "12")["foo"].must == "12"
166
+ end
167
+
168
+ it "accepts a switch=<value> assignment" do
169
+ parse("-f=12")["foo"].must == "12"
170
+ parse("--foo=12")["foo"].must == "12"
171
+ parse("--foo=bar=baz")["foo"].must == "bar=baz"
172
+ end
173
+
174
+ it "accepts a --no-switch format" do
175
+ create "--foo" => "bar"
176
+ parse("--no-foo")["foo"].must be_nil
177
+ end
178
+
179
+ it "accepts a --switch format on non required types" do
180
+ create "--foo" => :string
181
+ parse("--foo")["foo"].must == "foo"
182
+ end
183
+
184
+ it "accepts a --switch format on non required types with default values" do
185
+ create "--baz" => :string, "--foo" => "bar"
186
+ parse("--baz", "bang", "--foo")["foo"].must == "bar"
187
+ end
188
+
189
+ it "overwrites earlier values with later values" do
190
+ parse("--foo=bar", "--foo", "12")["foo"].must == "12"
191
+ parse("--foo", "12", "--foo", "13")["foo"].must == "13"
192
+ end
193
+ end
194
+
195
+ describe "with :boolean type" do
196
+ before(:each) do
197
+ create "--foo" => false
198
+ end
199
+
200
+ it "accepts --opt assignment" do
201
+ parse("--foo")["foo"].must == true
202
+ parse("--foo", "--bar")["foo"].must == true
203
+ end
204
+
205
+ it "accepts --opt=value assignment" do
206
+ parse("--foo=true")["foo"].must == true
207
+ parse("--foo=false")["foo"].must == false
208
+ end
209
+
210
+ it "accepts --[no-]opt variant, setting false for value" do
211
+ parse("--no-foo")["foo"].must == false
212
+ end
213
+
214
+ it "accepts --[skip-]opt variant, setting false for value" do
215
+ parse("--skip-foo")["foo"].must == false
216
+ end
217
+
218
+ it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do
219
+ create "--no-foo" => true
220
+ parse("--no-foo")["no-foo"].must == true
221
+ end
222
+
223
+ it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do
224
+ create "--skip-foo" => true
225
+ parse("--skip-foo")["skip-foo"].must == true
226
+ end
227
+
228
+ it "accepts inputs in the human name format" do
229
+ create :foo_bar => :boolean
230
+ parse("--foo-bar")["foo_bar"].must == true
231
+ parse("--no-foo-bar")["foo_bar"].must == false
232
+ parse("--skip-foo-bar")["foo_bar"].must == false
233
+ end
234
+ end
235
+
236
+ describe "with :hash type" do
237
+ before(:each) do
238
+ create "--attributes" => :hash
239
+ end
240
+
241
+ it "accepts a switch=<value> assignment" do
242
+ parse("--attributes=name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"}
243
+ end
244
+
245
+ it "accepts a switch <value> assignment" do
246
+ parse("--attributes", "name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"}
247
+ end
248
+
249
+ it "must not mix values with other switches" do
250
+ parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].must == {"name" => "string", "age" => "integer"}
251
+ end
252
+ end
253
+
254
+ describe "with :array type" do
255
+ before(:each) do
256
+ create "--attributes" => :array
257
+ end
258
+
259
+ it "accepts a switch=<value> assignment" do
260
+ parse("--attributes=a", "b", "c")["attributes"].must == ["a", "b", "c"]
261
+ end
262
+
263
+ it "accepts a switch <value> assignment" do
264
+ parse("--attributes", "a", "b", "c")["attributes"].must == ["a", "b", "c"]
265
+ end
266
+
267
+ it "must not mix values with other switches" do
268
+ parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].must == ["a", "b", "c"]
269
+ end
270
+ end
271
+
272
+ describe "with :numeric type" do
273
+ before(:each) do
274
+ create "n" => :numeric, "m" => 5
275
+ end
276
+
277
+ it "accepts a -nXY assignment" do
278
+ parse("-n12")["n"].must == 12
279
+ end
280
+
281
+ it "converts values to numeric types" do
282
+ parse("-n", "3", "-m", ".5").must == {"n" => 3, "m" => 0.5}
283
+ end
284
+
285
+ it "raises error when value isn't numeric" do
286
+ lambda { parse("-n", "foo") }.must raise_error(Thor::MalformattedArgumentError,
287
+ "Expected numeric value for '-n'; got \"foo\"")
288
+ end
289
+ end
290
+
291
+ end
292
+ 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"].must include(Rake.application.rakefile)
32
+ end
33
+
34
+ it "adds rake tasks to thor classes too" do
35
+ task = ThorTask.tasks["cool"]
36
+ task.must be
37
+ end
38
+
39
+ it "uses rake tasks descriptions on thor" do
40
+ ThorTask.tasks["cool"].description.must == "Say it's cool"
41
+ end
42
+
43
+ it "gets usage from rake tasks name" do
44
+ ThorTask.tasks["cool"].usage.must == "cool"
45
+ end
46
+
47
+ it "uses non namespaced name as description if non is available" do
48
+ ThorTask::HiperMega.tasks["super"].description.must == "super"
49
+ end
50
+
51
+ it "converts namespaces to classes" do
52
+ ThorTask.const_get(:HiperMega).must == ThorTask::HiperMega
53
+ end
54
+
55
+ it "does not add tasks from higher namespaces in lowers namespaces" do
56
+ ThorTask.tasks["super"].must_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.must == "COOL\n"
63
+
64
+ capture(:stdout) do
65
+ ThorTask::HiperMega.start ["super"]
66
+ end.must == "HIPER MEGA SUPER\n"
67
+ end
68
+ 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"]) }.must =~ /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.must =~ /List the available thor tasks/
13
+ content.must_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.must =~ /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.must =~ /zoo around/
24
+ content.must_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.must =~ /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.must == '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 }.must =~ /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.must 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.must == "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.must == ["horse"]
57
+ end
58
+
59
+ it "invokes tasks through shortcuts" do
60
+ ARGV.replace ["my_script", "-T", "horse"]
61
+ Thor::Runner.start.must == ["horse"]
62
+ end
63
+
64
+ it "invokes a Thor::Group" do
65
+ ARGV.replace ["my_counter", "1", "2", "--third", "3"]
66
+ Thor::Runner.start.must == [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.must == '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 }.must 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 }.must 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.must == '"animal" was called incorrectly. Call as "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.must =~ /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 }.must =~ /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 }.must =~ /amazing:describe NAME/
126
+ ARGV.replace []
127
+ capture(:stdout) { Thor::Runner.start }.must_not =~ /my_script:animal TYPE/
128
+ ARGV.replace ["list", "--group", "script"]
129
+ capture(:stdout) { Thor::Runner.start }.must =~ /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.must =~ /amazing:describe NAME/
136
+ content.must =~ /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 }.must_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 }.must =~ /^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 }.must == "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 }.must == "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 }.must == "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.must =~ /random\s*amazing/
184
+ stdout.must =~ /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