Skip to content

Commit feed0e8

Browse files
MaxLaperegon
authored andcommitted
Use remove_const after specs which set constants
# Conflicts: # core/kernel/eval_spec.rb
1 parent 129150d commit feed0e8

29 files changed

+271
-2
lines changed

core/basicobject/singleton_method_added_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def self.foo
9696
end
9797
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for/)
9898
end
99+
ensure
100+
BasicObjectSpecs.send(:remove_const, :NoSingletonMethodAdded)
99101
end
100102

101103
it "raises NoMethodError for a singleton instance" do

core/class/dup_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def self.message
5959
it "stores the new name if assigned to a constant" do
6060
CoreClassSpecs::RecordCopy = CoreClassSpecs::Record.dup
6161
CoreClassSpecs::RecordCopy.name.should == "CoreClassSpecs::RecordCopy"
62+
ensure
63+
CoreClassSpecs.send(:remove_const, :RecordCopy)
6264
end
6365

6466
it "raises TypeError if called on BasicObject" do

core/class/new_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def message2; "hello"; end
8383
a = Class.new
8484
MyClass::NestedClass = a
8585
MyClass::NestedClass.name.should == "MyClass::NestedClass"
86+
ensure
87+
Object.send(:remove_const, :MyClass)
8688
end
8789

8890
it "sets the new class' superclass to the given class" do

core/exception/errno_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
ExceptionSpecs::EMFILESub = Class.new(Errno::EMFILE)
3030
exc = ExceptionSpecs::EMFILESub.new
3131
exc.should be_an_instance_of(ExceptionSpecs::EMFILESub)
32+
ensure
33+
ExceptionSpecs.send(:remove_const, :EMFILESub)
3234
end
3335
end
3436

core/exception/system_call_error_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def initialize
1616
exc = ExceptionSpecs::SCESub.new
1717
ScratchPad.recorded.should equal(:initialize)
1818
exc.should be_an_instance_of(ExceptionSpecs::SCESub)
19+
ensure
20+
ExceptionSpecs.send(:remove_const, :SCESub)
1921
end
2022
end
2123

core/kernel/eval_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ class EvalSpecs
313313
eval(code)
314314
EvalSpecs.constants(false).should include(:"Vπ")
315315
EvalSpecs::.should == 3.14
316+
ensure
317+
EvalSpecs.send(:remove_const, :Vπ)
316318
end
317319

318320
it "allows an emacs-style magic comment encoding" do
@@ -326,6 +328,8 @@ class EvalSpecs
326328
eval(code)
327329
EvalSpecs.constants(false).should include(:"Vπemacs")
328330
EvalSpecs::Vπemacs.should == 3.14
331+
ensure
332+
EvalSpecs.send(:remove_const, :Vπemacs)
329333
end
330334

331335
it "allows spaces before the magic encoding comment" do
@@ -339,6 +343,8 @@ class EvalSpecs
339343
eval(code)
340344
EvalSpecs.constants(false).should include(:"Vπspaces")
341345
EvalSpecs::Vπspaces.should == 3.14
346+
ensure
347+
EvalSpecs.send(:remove_const, :Vπspaces)
342348
end
343349

344350
it "allows a shebang line before the magic encoding comment" do
@@ -353,6 +359,8 @@ class EvalSpecs
353359
eval(code)
354360
EvalSpecs.constants(false).should include(:"Vπshebang")
355361
EvalSpecs::Vπshebang.should == 3.14
362+
ensure
363+
EvalSpecs.send(:remove_const, :Vπshebang)
356364
end
357365

358366
it "allows a shebang line and some spaces before the magic encoding comment" do
@@ -367,6 +375,8 @@ class EvalSpecs
367375
eval(code)
368376
EvalSpecs.constants(false).should include(:"Vπshebang_spaces")
369377
EvalSpecs::Vπshebang_spaces.should == 3.14
378+
ensure
379+
EvalSpecs.send(:remove_const, :Vπshebang_spaces)
370380
end
371381

372382
it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do
@@ -385,6 +395,8 @@ class EvalSpecs
385395
EvalSpecs::Vπstring.should == "frozen"
386396
EvalSpecs::Vπstring.encoding.should == Encoding::UTF_8
387397
EvalSpecs::Vπstring.frozen?.should == !frozen_string_default
398+
ensure
399+
EvalSpecs.send(:remove_const, :Vπstring)
388400
end
389401

390402
it "allows a magic encoding comment and a frozen_string_literal magic comment on the same line in emacs style" do
@@ -400,6 +412,8 @@ class EvalSpecs
400412
EvalSpecs::Vπsame_line.should == "frozen"
401413
EvalSpecs::Vπsame_line.encoding.should == Encoding::UTF_8
402414
EvalSpecs::Vπsame_line.frozen?.should be_true
415+
ensure
416+
EvalSpecs.send(:remove_const, :Vπsame_line)
403417
end
404418

405419
it "ignores the magic encoding comment if it is after a frozen_string_literal magic comment" do
@@ -420,6 +434,8 @@ class EvalSpecs
420434
value.should == "frozen"
421435
value.encoding.should == Encoding::BINARY
422436
value.frozen?.should == !frozen_string_default
437+
ensure
438+
EvalSpecs.send(:remove_const, binary_constant)
423439
end
424440

425441
it "ignores the frozen_string_literal magic comment if it appears after a token and warns if $VERBOSE is true" do

core/module/const_defined_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
str = "CS_CONSTλ".encode("euc-jp")
6666
ConstantSpecs.const_set str, 1
6767
ConstantSpecs.const_defined?(str).should be_true
68+
ensure
69+
ConstantSpecs.send(:remove_const, str)
6870
end
6971

7072
it "returns false if the constant is not defined in the receiver, its superclass, or any included modules" do

core/module/const_get_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,40 +202,60 @@
202202

203203
ConstantSpecs::ContainerA::ChildA::CS_CONST301 = :const301_5
204204
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST301).should == :const301_5
205+
ensure
206+
ConstantSpecs::ClassA.send(:remove_const, :CS_CONST301)
207+
ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST301)
208+
ConstantSpecs::ParentA.send(:remove_const, :CS_CONST301)
209+
ConstantSpecs::ContainerA::ChildA.send(:remove_const, :CS_CONST301)
205210
end
206211

207212
it "searches a module included in the immediate class before the superclass" do
208213
ConstantSpecs::ParentB::CS_CONST302 = :const302_1
209214
ConstantSpecs::ModuleF::CS_CONST302 = :const302_2
210215
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST302).should == :const302_2
216+
ensure
217+
ConstantSpecs::ParentB.send(:remove_const, :CS_CONST302)
218+
ConstantSpecs::ModuleF.send(:remove_const, :CS_CONST302)
211219
end
212220

213221
it "searches the superclass before a module included in the superclass" do
214222
ConstantSpecs::ModuleE::CS_CONST303 = :const303_1
215223
ConstantSpecs::ParentB::CS_CONST303 = :const303_2
216224
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST303).should == :const303_2
225+
ensure
226+
ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST303)
227+
ConstantSpecs::ParentB.send(:remove_const, :CS_CONST303)
217228
end
218229

219230
it "searches a module included in the superclass" do
220231
ConstantSpecs::ModuleA::CS_CONST304 = :const304_1
221232
ConstantSpecs::ModuleE::CS_CONST304 = :const304_2
222233
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST304).should == :const304_2
234+
ensure
235+
ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST304)
236+
ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST304)
223237
end
224238

225239
it "searches the superclass chain" do
226240
ConstantSpecs::ModuleA::CS_CONST305 = :const305
227241
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST305).should == :const305
242+
ensure
243+
ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST305)
228244
end
229245

230246
it "returns a toplevel constant when the receiver is a Class" do
231247
Object::CS_CONST306 = :const306
232248
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST306).should == :const306
249+
ensure
250+
Object.send(:remove_const, :CS_CONST306)
233251
end
234252

235253
it "returns a toplevel constant when the receiver is a Module" do
236254
Object::CS_CONST308 = :const308
237255
ConstantSpecs.const_get(:CS_CONST308).should == :const308
238256
ConstantSpecs::ModuleA.const_get(:CS_CONST308).should == :const308
257+
ensure
258+
Object.send(:remove_const, :CS_CONST308)
239259
end
240260

241261
it "returns the updated value of a constant" do
@@ -246,6 +266,8 @@
246266
ConstantSpecs::ClassB::CS_CONST309 = :const309_2
247267
}.should complain(/already initialized constant/)
248268
ConstantSpecs::ClassB.const_get(:CS_CONST309).should == :const309_2
269+
ensure
270+
ConstantSpecs::ClassB.send(:remove_const, :CS_CONST309)
249271
end
250272
end
251273
end

core/module/const_set_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@
88

99
ConstantSpecs.const_set "CS_CONST402", :const402
1010
ConstantSpecs.const_get(:CS_CONST402).should == :const402
11+
ensure
12+
ConstantSpecs.send(:remove_const, :CS_CONST401)
13+
ConstantSpecs.send(:remove_const, :CS_CONST402)
1114
end
1215

1316
it "returns the value set" do
1417
ConstantSpecs.const_set(:CS_CONST403, :const403).should == :const403
18+
ensure
19+
ConstantSpecs.send(:remove_const, :CS_CONST403)
1520
end
1621

1722
it "sets the name of an anonymous module" do
1823
m = Module.new
1924
ConstantSpecs.const_set(:CS_CONST1000, m)
2025
m.name.should == "ConstantSpecs::CS_CONST1000"
26+
ensure
27+
ConstantSpecs.send(:remove_const, :CS_CONST1000)
2128
end
2229

2330
it "sets the name of a module scoped by an anonymous module" do
@@ -38,6 +45,8 @@
3845
b.name.should == "ModuleSpecs_CS3::B"
3946
c.name.should == "ModuleSpecs_CS3::B::C"
4047
d.name.should == "ModuleSpecs_CS3::D"
48+
ensure
49+
Object.send(:remove_const, :ModuleSpecs_CS3)
4150
end
4251

4352
it "raises a NameError if the name does not start with a capital letter" do
@@ -55,13 +64,17 @@
5564
ConstantSpecs.const_set("CS_CONST404", :const404).should == :const404
5665
-> { ConstantSpecs.const_set "Name=", 1 }.should raise_error(NameError)
5766
-> { ConstantSpecs.const_set "Name?", 1 }.should raise_error(NameError)
67+
ensure
68+
ConstantSpecs.send(:remove_const, :CS_CONST404)
5869
end
5970

6071
it "calls #to_str to convert the given name to a String" do
6172
name = mock("CS_CONST405")
6273
name.should_receive(:to_str).and_return("CS_CONST405")
6374
ConstantSpecs.const_set(name, :const405).should == :const405
6475
ConstantSpecs::CS_CONST405.should == :const405
76+
ensure
77+
ConstantSpecs.send(:remove_const, :CS_CONST405)
6578
end
6679

6780
it "raises a TypeError if conversion to a String by calling #to_str fails" do

core/module/const_source_location_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,60 @@
1919

2020
ConstantSpecs::ContainerA::ChildA::CSL_CONST301 = :const301_5
2121
ConstantSpecs::ContainerA::ChildA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
22+
ensure
23+
ConstantSpecs::ClassA.send(:remove_const, :CSL_CONST301)
24+
ConstantSpecs::ModuleA.send(:remove_const, :CSL_CONST301)
25+
ConstantSpecs::ParentA.send(:remove_const, :CSL_CONST301)
26+
ConstantSpecs::ContainerA::ChildA.send(:remove_const, :CSL_CONST301)
2227
end
2328

2429
it "searches a path in a module included in the immediate class before the superclass" do
2530
ConstantSpecs::ParentB::CSL_CONST302 = :const302_1
2631
ConstantSpecs::ModuleF::CSL_CONST302 = :const302_2
2732
ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST302).should == [__FILE__, __LINE__ - 1]
33+
ensure
34+
ConstantSpecs::ParentB.send(:remove_const, :CSL_CONST302)
35+
ConstantSpecs::ModuleF.send(:remove_const, :CSL_CONST302)
2836
end
2937

3038
it "searches a path in the superclass before a module included in the superclass" do
3139
ConstantSpecs::ModuleE::CSL_CONST303 = :const303_1
3240
ConstantSpecs::ParentB::CSL_CONST303 = :const303_2
3341
ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST303).should == [__FILE__, __LINE__ - 1]
42+
ensure
43+
ConstantSpecs::ModuleE.send(:remove_const, :CSL_CONST303)
44+
ConstantSpecs::ParentB.send(:remove_const, :CSL_CONST303)
3445
end
3546

3647
it "searches a path in a module included in the superclass" do
3748
ConstantSpecs::ModuleA::CSL_CONST304 = :const304_1
3849
ConstantSpecs::ModuleE::CSL_CONST304 = :const304_2
3950
ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST304).should == [__FILE__, __LINE__ - 1]
51+
ensure
52+
ConstantSpecs::ModuleA.send(:remove_const, :CSL_CONST304)
53+
ConstantSpecs::ModuleE.send(:remove_const, :CSL_CONST304)
4054
end
4155

4256
it "searches a path in the superclass chain" do
4357
ConstantSpecs::ModuleA::CSL_CONST305 = :const305
4458
ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST305).should == [__FILE__, __LINE__ - 1]
59+
ensure
60+
ConstantSpecs::ModuleA.send(:remove_const, :CSL_CONST305)
4561
end
4662

4763
it "returns path to a toplevel constant when the receiver is a Class" do
4864
Object::CSL_CONST306 = :const306
4965
ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST306).should == [__FILE__, __LINE__ - 1]
66+
ensure
67+
Object.send(:remove_const, :CSL_CONST306)
5068
end
5169

5270
it "returns path to a toplevel constant when the receiver is a Module" do
5371
Object::CSL_CONST308 = :const308
5472
ConstantSpecs.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 1]
5573
ConstantSpecs::ModuleA.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 2]
74+
ensure
75+
Object.send(:remove_const, :CSL_CONST308)
5676
end
5777

5878
it "returns path to the updated value of a constant" do
@@ -63,6 +83,8 @@
6383
ConstantSpecs::ClassB::CSL_CONST309 = :const309_2
6484
}.should complain(/already initialized constant/)
6585
ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 2]
86+
ensure
87+
ConstantSpecs::ClassB.send(:remove_const, :CSL_CONST309)
6688
end
6789
end
6890

0 commit comments

Comments
 (0)