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