Skip to content

Commit 2acb1a6

Browse files
nobuandrykonchin
authored andcommitted
[Feature #15408] Fix up _id2ref_spec.rb
1 parent 1d008f7 commit 2acb1a6

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

core/objectspace/_id2ref_spec.rb

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,65 @@
11
require_relative '../../spec_helper'
22

3-
describe "ObjectSpace._id2ref" do
4-
it "converts an object id to a reference to the object" do
5-
s = "I am a string"
6-
r = ObjectSpace._id2ref(s.object_id)
7-
r.should == s
3+
ruby_version_is "3.5" do
4+
describe "ObjectSpace._id2ref" do
5+
it "is deprecated" do
6+
id = nil.object_id
7+
-> {
8+
ObjectSpace._id2ref(id)
9+
}.should complain(/warning: ObjectSpace\._id2ref is deprecated/)
10+
end
811
end
12+
end
913

10-
it "retrieves true by object_id" do
11-
ObjectSpace._id2ref(true.object_id).should == true
12-
end
14+
ruby_version_is ""..."3.5" do
15+
describe "ObjectSpace._id2ref" do
16+
it "converts an object id to a reference to the object" do
17+
s = "I am a string"
18+
r = ObjectSpace._id2ref(s.object_id)
19+
r.should == s
20+
end
1321

14-
it "retrieves false by object_id" do
15-
ObjectSpace._id2ref(false.object_id).should == false
16-
end
22+
it "retrieves true by object_id" do
23+
ObjectSpace._id2ref(true.object_id).should == true
24+
end
1725

18-
it "retrieves nil by object_id" do
19-
ObjectSpace._id2ref(nil.object_id).should == nil
20-
end
26+
it "retrieves false by object_id" do
27+
ObjectSpace._id2ref(false.object_id).should == false
28+
end
2129

22-
it "retrieves a small Integer by object_id" do
23-
ObjectSpace._id2ref(1.object_id).should == 1
24-
ObjectSpace._id2ref((-42).object_id).should == -42
25-
end
30+
it "retrieves nil by object_id" do
31+
ObjectSpace._id2ref(nil.object_id).should == nil
32+
end
2633

27-
it "retrieves a large Integer by object_id" do
28-
obj = 1 << 88
29-
ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
30-
end
34+
it "retrieves a small Integer by object_id" do
35+
ObjectSpace._id2ref(1.object_id).should == 1
36+
ObjectSpace._id2ref((-42).object_id).should == -42
37+
end
3138

32-
it "retrieves a Symbol by object_id" do
33-
ObjectSpace._id2ref(:sym.object_id).should.equal?(:sym)
34-
end
39+
it "retrieves a large Integer by object_id" do
40+
obj = 1 << 88
41+
ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
42+
end
3543

36-
it "retrieves a String by object_id" do
37-
obj = "str"
38-
ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
39-
end
44+
it "retrieves a Symbol by object_id" do
45+
ObjectSpace._id2ref(:sym.object_id).should.equal?(:sym)
46+
end
4047

41-
it "retrieves a frozen literal String by object_id" do
42-
ObjectSpace._id2ref("frozen string literal _id2ref".freeze.object_id).should.equal?("frozen string literal _id2ref".freeze)
43-
end
48+
it "retrieves a String by object_id" do
49+
obj = "str"
50+
ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
51+
end
4452

45-
it "retrieves an Encoding by object_id" do
46-
ObjectSpace._id2ref(Encoding::UTF_8.object_id).should.equal?(Encoding::UTF_8)
47-
end
53+
it "retrieves a frozen literal String by object_id" do
54+
ObjectSpace._id2ref("frozen string literal _id2ref".freeze.object_id).should.equal?("frozen string literal _id2ref".freeze)
55+
end
56+
57+
it "retrieves an Encoding by object_id" do
58+
ObjectSpace._id2ref(Encoding::UTF_8.object_id).should.equal?(Encoding::UTF_8)
59+
end
4860

49-
it 'raises RangeError when an object could not be found' do
50-
proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
61+
it 'raises RangeError when an object could not be found' do
62+
proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
63+
end
5164
end
5265
end

0 commit comments

Comments
 (0)