thor 0.16.0 → 1.2.1
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.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +15 -0
- data/README.md +23 -6
- data/bin/thor +1 -1
- data/lib/thor/actions/create_file.rb +34 -35
- data/lib/thor/actions/create_link.rb +9 -5
- data/lib/thor/actions/directory.rb +33 -23
- data/lib/thor/actions/empty_directory.rb +75 -85
- data/lib/thor/actions/file_manipulation.rb +103 -36
- data/lib/thor/actions/inject_into_file.rb +46 -36
- data/lib/thor/actions.rb +90 -68
- data/lib/thor/base.rb +302 -244
- data/lib/thor/command.rb +142 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +52 -24
- data/lib/thor/error.rb +90 -10
- data/lib/thor/group.rb +70 -74
- data/lib/thor/invocation.rb +63 -55
- data/lib/thor/line_editor/basic.rb +37 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/nested_context.rb +29 -0
- data/lib/thor/parser/argument.rb +24 -28
- data/lib/thor/parser/arguments.rb +110 -102
- data/lib/thor/parser/option.rb +53 -15
- data/lib/thor/parser/options.rb +174 -97
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/rake_compat.rb +12 -11
- data/lib/thor/runner.rb +159 -155
- data/lib/thor/shell/basic.rb +216 -93
- data/lib/thor/shell/color.rb +53 -40
- data/lib/thor/shell/html.rb +61 -58
- data/lib/thor/shell.rb +29 -36
- data/lib/thor/util.rb +231 -213
- data/lib/thor/version.rb +1 -1
- data/lib/thor.rb +303 -166
- data/thor.gemspec +27 -24
- metadata +36 -226
- data/.gitignore +0 -44
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/CHANGELOG.rdoc +0 -134
- data/Gemfile +0 -15
- data/Thorfile +0 -30
- data/bin/rake2thor +0 -86
- data/lib/thor/core_ext/dir_escape.rb +0 -0
- data/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/lib/thor/core_ext/ordered_hash.rb +0 -100
- data/lib/thor/task.rb +0 -132
- data/spec/actions/create_file_spec.rb +0 -170
- data/spec/actions/create_link_spec.rb +0 -81
- data/spec/actions/directory_spec.rb +0 -149
- data/spec/actions/empty_directory_spec.rb +0 -130
- data/spec/actions/file_manipulation_spec.rb +0 -370
- data/spec/actions/inject_into_file_spec.rb +0 -135
- data/spec/actions_spec.rb +0 -331
- data/spec/base_spec.rb +0 -279
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -43
- data/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/spec/exit_condition_spec.rb +0 -19
- data/spec/fixtures/application.rb +0 -2
- data/spec/fixtures/app{1}/README +0 -3
- data/spec/fixtures/bundle/execute.rb +0 -6
- data/spec/fixtures/bundle/main.thor +0 -1
- data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
- data/spec/fixtures/doc/COMMENTER +0 -10
- data/spec/fixtures/doc/README +0 -3
- data/spec/fixtures/doc/block_helper.rb +0 -3
- data/spec/fixtures/doc/components/.empty_directory +0 -0
- data/spec/fixtures/doc/config.rb +0 -1
- data/spec/fixtures/doc/config.yaml.tt +0 -1
- data/spec/fixtures/enum.thor +0 -10
- data/spec/fixtures/group.thor +0 -114
- data/spec/fixtures/invoke.thor +0 -112
- data/spec/fixtures/path with spaces +0 -0
- data/spec/fixtures/script.thor +0 -190
- data/spec/fixtures/task.thor +0 -10
- data/spec/group_spec.rb +0 -216
- data/spec/invocation_spec.rb +0 -100
- data/spec/parser/argument_spec.rb +0 -53
- data/spec/parser/arguments_spec.rb +0 -66
- data/spec/parser/option_spec.rb +0 -202
- data/spec/parser/options_spec.rb +0 -330
- data/spec/rake_compat_spec.rb +0 -72
- data/spec/register_spec.rb +0 -135
- data/spec/runner_spec.rb +0 -241
- data/spec/shell/basic_spec.rb +0 -300
- data/spec/shell/color_spec.rb +0 -81
- data/spec/shell/html_spec.rb +0 -32
- data/spec/shell_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -59
- data/spec/task_spec.rb +0 -80
- data/spec/thor_spec.rb +0 -418
- data/spec/util_spec.rb +0 -196
data/spec/base_spec.rb
DELETED
@@ -1,279 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'thor/base'
|
3
|
-
|
4
|
-
class Amazing
|
5
|
-
desc "hello", "say hello"
|
6
|
-
def hello
|
7
|
-
puts "Hello"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Thor::Base do
|
12
|
-
describe "#initialize" do
|
13
|
-
it "sets arguments array" do
|
14
|
-
base = MyCounter.new [1, 2]
|
15
|
-
base.first.should == 1
|
16
|
-
base.second.should == 2
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets arguments default values" do
|
20
|
-
base = MyCounter.new [1]
|
21
|
-
base.second.should == 2
|
22
|
-
end
|
23
|
-
|
24
|
-
it "sets options default values" do
|
25
|
-
base = MyCounter.new [1, 2]
|
26
|
-
base.options[:third].should == 3
|
27
|
-
end
|
28
|
-
|
29
|
-
it "allows options to be given as symbols or strings" do
|
30
|
-
base = MyCounter.new [1, 2], :third => 4
|
31
|
-
base.options[:third].should == 4
|
32
|
-
|
33
|
-
base = MyCounter.new [1, 2], "third" => 4
|
34
|
-
base.options[:third].should == 4
|
35
|
-
end
|
36
|
-
|
37
|
-
it "creates options with indifferent access" do
|
38
|
-
base = MyCounter.new [1, 2], :third => 3
|
39
|
-
base.options['third'].should == 3
|
40
|
-
end
|
41
|
-
|
42
|
-
it "creates options with magic predicates" do
|
43
|
-
base = MyCounter.new [1, 2], :third => 3
|
44
|
-
base.options.third.should == 3
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#no_tasks" do
|
49
|
-
it "avoids methods being added as tasks" do
|
50
|
-
MyScript.tasks.keys.should include("animal")
|
51
|
-
MyScript.tasks.keys.should_not include("this_is_not_a_task")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#argument" do
|
56
|
-
it "sets a value as required and creates an accessor for it" do
|
57
|
-
MyCounter.start(["1", "2", "--third", "3"])[0].should == 1
|
58
|
-
Scripts::MyScript.start(["zoo", "my_special_param", "--param=normal_param"]).should == "my_special_param"
|
59
|
-
end
|
60
|
-
|
61
|
-
it "does not set a value in the options hash" do
|
62
|
-
BrokenCounter.start(["1", "2", "--third", "3"])[0].should be_nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#arguments" do
|
67
|
-
it "returns the arguments for the class" do
|
68
|
-
MyCounter.arguments.should have(2).items
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#class_option" do
|
73
|
-
it "sets options class wise" do
|
74
|
-
MyCounter.start(["1", "2", "--third", "3"])[2].should == 3
|
75
|
-
end
|
76
|
-
|
77
|
-
it "does not create an accessor for it" do
|
78
|
-
BrokenCounter.start(["1", "2", "--third", "3"])[3].should be_false
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#class_options" do
|
83
|
-
it "sets default options overwriting superclass definitions" do
|
84
|
-
options = Scripts::MyScript.class_options
|
85
|
-
options[:force].should_not be_required
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#remove_argument" do
|
90
|
-
it "removes previous defined arguments from class" do
|
91
|
-
ClearCounter.arguments.should be_empty
|
92
|
-
end
|
93
|
-
|
94
|
-
it "undefine accessors if required" do
|
95
|
-
ClearCounter.new.should_not respond_to(:first)
|
96
|
-
ClearCounter.new.should_not respond_to(:second)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "#remove_class_option" do
|
101
|
-
it "removes previous defined class option" do
|
102
|
-
ClearCounter.class_options[:third].should be_nil
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "#class_options_help" do
|
107
|
-
before do
|
108
|
-
@content = capture(:stdout) { MyCounter.help(Thor::Base.shell.new) }
|
109
|
-
end
|
110
|
-
|
111
|
-
it "shows options description" do
|
112
|
-
@content.should =~ /# The third argument/
|
113
|
-
end
|
114
|
-
|
115
|
-
it "shows usage with banner content" do
|
116
|
-
@content.should =~ /\[\-\-third=THREE\]/
|
117
|
-
end
|
118
|
-
|
119
|
-
it "shows default values below description" do
|
120
|
-
@content.should =~ /# Default: 3/
|
121
|
-
end
|
122
|
-
|
123
|
-
it "shows options in different groups" do
|
124
|
-
@content.should =~ /Options\:/
|
125
|
-
@content.should =~ /Runtime options\:/
|
126
|
-
@content.should =~ /\-p, \[\-\-pretend\]/
|
127
|
-
end
|
128
|
-
|
129
|
-
it "use padding in options that does not have aliases" do
|
130
|
-
@content.should =~ /^ -t, \[--third/
|
131
|
-
@content.should =~ /^ \[--fourth/
|
132
|
-
end
|
133
|
-
|
134
|
-
it "allows extra options to be given" do
|
135
|
-
hash = { "Foo" => B.class_options.values }
|
136
|
-
|
137
|
-
content = capture(:stdout) { MyCounter.send(:class_options_help, Thor::Base.shell.new, hash) }
|
138
|
-
content.should =~ /Foo options\:/
|
139
|
-
content.should =~ /--last-name=LAST_NAME/
|
140
|
-
end
|
141
|
-
|
142
|
-
it "displays choices for enums" do
|
143
|
-
content = capture(:stdout) { Enum.help(Thor::Base.shell.new) }
|
144
|
-
content.should =~ /Possible values\: apple, banana/
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "#namespace" do
|
149
|
-
it "returns the default class namespace" do
|
150
|
-
Scripts::MyScript.namespace.should == "scripts:my_script"
|
151
|
-
end
|
152
|
-
|
153
|
-
it "sets a namespace to the class" do
|
154
|
-
Scripts::MyDefaults.namespace.should == "default"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe "#group" do
|
159
|
-
it "sets a group" do
|
160
|
-
MyScript.group.should == "script"
|
161
|
-
end
|
162
|
-
|
163
|
-
it "inherits the group from parent" do
|
164
|
-
MyChildScript.group.should == "script"
|
165
|
-
end
|
166
|
-
|
167
|
-
it "defaults to standard if no group is given" do
|
168
|
-
Amazing.group.should == "standard"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "#subclasses" do
|
173
|
-
it "tracks its subclasses in an Array" do
|
174
|
-
Thor::Base.subclasses.should include(MyScript)
|
175
|
-
Thor::Base.subclasses.should include(MyChildScript)
|
176
|
-
Thor::Base.subclasses.should include(Scripts::MyScript)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "#subclass_files" do
|
181
|
-
it "returns tracked subclasses, grouped by the files they come from" do
|
182
|
-
thorfile = File.join(File.dirname(__FILE__), "fixtures", "script.thor")
|
183
|
-
Thor::Base.subclass_files[File.expand_path(thorfile)].should == [
|
184
|
-
MyScript, MyScript::AnotherScript, MyChildScript, Barn,
|
185
|
-
Scripts::MyScript, Scripts::MyDefaults, Scripts::ChildDefault
|
186
|
-
]
|
187
|
-
end
|
188
|
-
|
189
|
-
it "tracks a single subclass across multiple files" do
|
190
|
-
thorfile = File.join(File.dirname(__FILE__), "fixtures", "task.thor")
|
191
|
-
Thor::Base.subclass_files[File.expand_path(thorfile)].should include(Amazing)
|
192
|
-
Thor::Base.subclass_files[File.expand_path(__FILE__)].should include(Amazing)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
describe "#tasks" do
|
197
|
-
it "returns a list with all tasks defined in this class" do
|
198
|
-
MyChildScript.new.should respond_to("animal")
|
199
|
-
MyChildScript.tasks.keys.should include("animal")
|
200
|
-
end
|
201
|
-
|
202
|
-
it "raises an error if a task with reserved word is defined" do
|
203
|
-
lambda {
|
204
|
-
klass = Class.new(Thor::Group)
|
205
|
-
klass.class_eval "def shell; end"
|
206
|
-
}.should raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as task/)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe "#all_tasks" do
|
211
|
-
it "returns a list with all tasks defined in this class plus superclasses" do
|
212
|
-
MyChildScript.new.should respond_to("foo")
|
213
|
-
MyChildScript.all_tasks.keys.should include("foo")
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "#remove_task" do
|
218
|
-
it "removes the task from its tasks hash" do
|
219
|
-
MyChildScript.tasks.keys.should_not include("bar")
|
220
|
-
MyChildScript.tasks.keys.should_not include("boom")
|
221
|
-
end
|
222
|
-
|
223
|
-
it "undefines the method if desired" do
|
224
|
-
MyChildScript.new.should_not respond_to("boom")
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "#from_superclass" do
|
229
|
-
it "does not send a method to the superclass if the superclass does not respond to it" do
|
230
|
-
MyCounter.get_from_super.should == 13
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "#start" do
|
235
|
-
it "raises an error instead of rescueing if THOR_DEBUG=1 is given" do
|
236
|
-
begin
|
237
|
-
ENV["THOR_DEBUG"] = 1
|
238
|
-
lambda {
|
239
|
-
MyScript.start ["what", "--debug"]
|
240
|
-
}.should raise_error(Thor::UndefinedTaskError, 'Could not find task "what" in "my_script" namespace.')
|
241
|
-
rescue
|
242
|
-
ENV["THOR_DEBUG"] = nil
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
it "does not steal args" do
|
247
|
-
args = ["foo", "bar", "--force", "true"]
|
248
|
-
MyScript.start(args)
|
249
|
-
args.should == ["foo", "bar", "--force", "true"]
|
250
|
-
end
|
251
|
-
|
252
|
-
it "checks unknown options" do
|
253
|
-
capture(:stderr) {
|
254
|
-
MyScript.start(["foo", "bar", "--force", "true", "--unknown", "baz"])
|
255
|
-
}.strip.should == "Unknown switches '--unknown'"
|
256
|
-
end
|
257
|
-
|
258
|
-
it "checks unknown options except specified" do
|
259
|
-
capture(:stderr) {
|
260
|
-
MyScript.start(["with_optional", "NAME", "--omg", "--invalid"]).should == ["NAME", {}, ["--omg", "--invalid"]]
|
261
|
-
}.strip.should be_empty
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe "attr_*" do
|
266
|
-
it "should not add attr_reader as a task" do
|
267
|
-
capture(:stderr){ MyScript.start(["another_attribute"]) }.should =~ /Could not find/
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should not add attr_writer as a task" do
|
271
|
-
capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }.should =~ /Could not find/
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should not add attr_accessor as a task" do
|
275
|
-
capture(:stderr){ MyScript.start(["some_attribute"]) }.should =~ /Could not find/
|
276
|
-
capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }.should =~ /Could not find/
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
require 'thor/core_ext/hash_with_indifferent_access'
|
3
|
-
|
4
|
-
describe Thor::CoreExt::HashWithIndifferentAccess do
|
5
|
-
before do
|
6
|
-
@hash = Thor::CoreExt::HashWithIndifferentAccess.new :foo => 'bar', 'baz' => 'bee', :force => true
|
7
|
-
end
|
8
|
-
|
9
|
-
it "has values accessible by either strings or symbols" do
|
10
|
-
@hash['foo'].should == 'bar'
|
11
|
-
@hash[:foo].should == 'bar'
|
12
|
-
|
13
|
-
@hash.values_at(:foo, :baz).should == ['bar', 'bee']
|
14
|
-
@hash.delete(:foo).should == 'bar'
|
15
|
-
end
|
16
|
-
|
17
|
-
it "handles magic boolean predicates" do
|
18
|
-
@hash.force?.should be_true
|
19
|
-
@hash.foo?.should be_true
|
20
|
-
@hash.nothing?.should be_false
|
21
|
-
end
|
22
|
-
|
23
|
-
it "handles magic comparisions" do
|
24
|
-
@hash.foo?('bar').should be_true
|
25
|
-
@hash.foo?('bee').should be_false
|
26
|
-
end
|
27
|
-
|
28
|
-
it "maps methods to keys" do
|
29
|
-
@hash.foo.should == @hash['foo']
|
30
|
-
end
|
31
|
-
|
32
|
-
it "merges keys independent if they are symbols or strings" do
|
33
|
-
@hash.merge!('force' => false, :baz => "boom")
|
34
|
-
@hash[:force].should == false
|
35
|
-
@hash[:baz].should == "boom"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "creates a new hash by merging keys independent if they are symbols or strings" do
|
39
|
-
other = @hash.merge('force' => false, :baz => "boom")
|
40
|
-
other[:force].should == false
|
41
|
-
other[:baz].should == "boom"
|
42
|
-
end
|
43
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
require 'thor/core_ext/ordered_hash'
|
3
|
-
|
4
|
-
describe Thor::CoreExt::OrderedHash do
|
5
|
-
before do
|
6
|
-
@hash = Thor::CoreExt::OrderedHash.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "without any items" do
|
10
|
-
it "returns nil for an undefined key" do
|
11
|
-
@hash["foo"].should be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "doesn't iterate through any items" do
|
15
|
-
@hash.each { fail }
|
16
|
-
end
|
17
|
-
|
18
|
-
it "has an empty key and values list" do
|
19
|
-
@hash.keys.should be_empty
|
20
|
-
@hash.values.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it "must be empty" do
|
24
|
-
@hash.should be_empty
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "with several items" do
|
29
|
-
before do
|
30
|
-
@hash[:foo] = "Foo!"
|
31
|
-
@hash[:bar] = "Bar!"
|
32
|
-
@hash[:baz] = "Baz!"
|
33
|
-
@hash[:bop] = "Bop!"
|
34
|
-
@hash[:bat] = "Bat!"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns nil for an undefined key" do
|
38
|
-
@hash[:boom].should be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns the value for each key" do
|
42
|
-
@hash[:foo].should == "Foo!"
|
43
|
-
@hash[:bar].should == "Bar!"
|
44
|
-
@hash[:baz].should == "Baz!"
|
45
|
-
@hash[:bop].should == "Bop!"
|
46
|
-
@hash[:bat].should == "Bat!"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "iterates through the keys and values in order of assignment" do
|
50
|
-
arr = []
|
51
|
-
@hash.each do |key, value|
|
52
|
-
arr << [key, value]
|
53
|
-
end
|
54
|
-
arr.should == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"],
|
55
|
-
[:bop, "Bop!"], [:bat, "Bat!"]]
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns the keys in order of insertion" do
|
59
|
-
@hash.keys.should == [:foo, :bar, :baz, :bop, :bat]
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns the values in order of insertion" do
|
63
|
-
@hash.values.should == ["Foo!", "Bar!", "Baz!", "Bop!", "Bat!"]
|
64
|
-
end
|
65
|
-
|
66
|
-
it "does not move an overwritten node to the end of the ordering" do
|
67
|
-
@hash[:baz] = "Bip!"
|
68
|
-
@hash.values.should == ["Foo!", "Bar!", "Bip!", "Bop!", "Bat!"]
|
69
|
-
|
70
|
-
@hash[:foo] = "Bip!"
|
71
|
-
@hash.values.should == ["Bip!", "Bar!", "Bip!", "Bop!", "Bat!"]
|
72
|
-
|
73
|
-
@hash[:bat] = "Bip!"
|
74
|
-
@hash.values.should == ["Bip!", "Bar!", "Bip!", "Bop!", "Bip!"]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "appends another ordered hash while preserving ordering" do
|
78
|
-
other_hash = Thor::CoreExt::OrderedHash.new
|
79
|
-
other_hash[1] = "one"
|
80
|
-
other_hash[2] = "two"
|
81
|
-
other_hash[3] = "three"
|
82
|
-
@hash.merge(other_hash).values.should == ["Foo!", "Bar!", "Baz!", "Bop!", "Bat!", "one", "two", "three"]
|
83
|
-
end
|
84
|
-
|
85
|
-
it "overwrites hash keys with matching appended keys" do
|
86
|
-
other_hash = Thor::CoreExt::OrderedHash.new
|
87
|
-
other_hash[:bar] = "bar"
|
88
|
-
@hash.merge(other_hash)[:bar].should == "bar"
|
89
|
-
@hash[:bar].should == "Bar!"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "converts to an array" do
|
93
|
-
@hash.to_a.should == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]]
|
94
|
-
end
|
95
|
-
|
96
|
-
it "must not be empty" do
|
97
|
-
@hash.should_not be_empty
|
98
|
-
end
|
99
|
-
|
100
|
-
it "deletes values from hash" do
|
101
|
-
@hash.delete(:baz).should == "Baz!"
|
102
|
-
@hash.values.should == ["Foo!", "Bar!", "Bop!", "Bat!"]
|
103
|
-
|
104
|
-
@hash.delete(:foo).should == "Foo!"
|
105
|
-
@hash.values.should == ["Bar!", "Bop!", "Bat!"]
|
106
|
-
|
107
|
-
@hash.delete(:bat).should == "Bat!"
|
108
|
-
@hash.values.should == ["Bar!", "Bop!"]
|
109
|
-
end
|
110
|
-
|
111
|
-
it "returns nil if the value to be deleted can't be found" do
|
112
|
-
@hash.delete(:nothing).should be_nil
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/spec/exit_condition_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'thor/base'
|
3
|
-
|
4
|
-
describe "Exit conditions" do
|
5
|
-
it "should exit 0, not bubble up EPIPE, if EPIPE is raised" do
|
6
|
-
epiped = false
|
7
|
-
|
8
|
-
task = Class.new(Thor) do
|
9
|
-
desc "my_action", "testing EPIPE"
|
10
|
-
define_method :my_action do
|
11
|
-
epiped = true
|
12
|
-
raise Errno::EPIPE
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
lambda { task.start(["my_action"]) }.should raise_error(SystemExit)
|
17
|
-
epiped.should == true
|
18
|
-
end
|
19
|
-
end
|
data/spec/fixtures/app{1}/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'execute')
|
@@ -1 +0,0 @@
|
|
1
|
-
FOO = <%= "FOO" %>
|
data/spec/fixtures/doc/COMMENTER
DELETED
data/spec/fixtures/doc/README
DELETED
File without changes
|
data/spec/fixtures/doc/config.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
class <%= @klass %>; end
|
@@ -1 +0,0 @@
|
|
1
|
-
--- Hi from yaml
|
data/spec/fixtures/enum.thor
DELETED
data/spec/fixtures/group.thor
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
class MyCounter < Thor::Group
|
2
|
-
include Thor::Actions
|
3
|
-
add_runtime_options!
|
4
|
-
|
5
|
-
def self.get_from_super
|
6
|
-
from_superclass(:get_from_super, 13)
|
7
|
-
end
|
8
|
-
|
9
|
-
source_root File.expand_path(File.dirname(__FILE__))
|
10
|
-
source_paths << File.expand_path("broken", File.dirname(__FILE__))
|
11
|
-
|
12
|
-
argument :first, :type => :numeric
|
13
|
-
argument :second, :type => :numeric, :default => 2
|
14
|
-
|
15
|
-
class_option :third, :type => :numeric, :desc => "The third argument", :default => 3,
|
16
|
-
:banner => "THREE", :aliases => "-t"
|
17
|
-
class_option :fourth, :type => :numeric, :desc => "The fourth argument"
|
18
|
-
|
19
|
-
desc <<-FOO
|
20
|
-
Description:
|
21
|
-
This generator runs three tasks: one, two and three.
|
22
|
-
FOO
|
23
|
-
|
24
|
-
def one
|
25
|
-
first
|
26
|
-
end
|
27
|
-
|
28
|
-
def two
|
29
|
-
second
|
30
|
-
end
|
31
|
-
|
32
|
-
def three
|
33
|
-
options[:third]
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.inherited(base)
|
37
|
-
super
|
38
|
-
base.source_paths.unshift(File.expand_path(File.join(File.dirname(__FILE__), "doc")))
|
39
|
-
end
|
40
|
-
|
41
|
-
no_tasks do
|
42
|
-
def world(&block)
|
43
|
-
result = capture(&block)
|
44
|
-
concat(result.strip + " world!")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class ClearCounter < MyCounter
|
50
|
-
remove_argument :first, :second, :undefine => true
|
51
|
-
remove_class_option :third
|
52
|
-
|
53
|
-
def self.source_root
|
54
|
-
File.expand_path(File.join(File.dirname(__FILE__), "bundle"))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class BrokenCounter < MyCounter
|
59
|
-
namespace "app:broken:counter"
|
60
|
-
class_option :fail, :type => :boolean, :default => false
|
61
|
-
|
62
|
-
class << self
|
63
|
-
undef_method :source_root
|
64
|
-
end
|
65
|
-
|
66
|
-
def one
|
67
|
-
options[:first]
|
68
|
-
end
|
69
|
-
|
70
|
-
def four
|
71
|
-
respond_to?(:fail)
|
72
|
-
end
|
73
|
-
|
74
|
-
def five
|
75
|
-
options[:fail] ? this_method_does_not_exist : 5
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class WhinyGenerator < Thor::Group
|
80
|
-
include Thor::Actions
|
81
|
-
|
82
|
-
def self.source_root
|
83
|
-
File.expand_path(File.dirname(__FILE__))
|
84
|
-
end
|
85
|
-
|
86
|
-
def wrong_arity(required)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class TaskConflict < Thor::Group
|
91
|
-
desc "A group with the same name as a default task"
|
92
|
-
def group
|
93
|
-
puts "group"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class ParentGroup < Thor::Group
|
98
|
-
private
|
99
|
-
def foo
|
100
|
-
"foo"
|
101
|
-
end
|
102
|
-
|
103
|
-
def baz(name = 'baz')
|
104
|
-
name
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class ChildGroup < ParentGroup
|
109
|
-
def bar
|
110
|
-
"bar"
|
111
|
-
end
|
112
|
-
|
113
|
-
public_task :foo, :baz
|
114
|
-
end
|