|
1 | 1 | require_relative '../../spec_helper'
|
2 | 2 |
|
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 |
8 | 11 | end
|
| 12 | +end |
9 | 13 |
|
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 |
13 | 21 |
|
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 |
17 | 25 |
|
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 |
21 | 29 |
|
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 |
26 | 33 |
|
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 |
31 | 38 |
|
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 |
35 | 43 |
|
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 |
40 | 47 |
|
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 |
44 | 52 |
|
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 |
48 | 60 |
|
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 |
51 | 64 | end
|
52 | 65 | end
|
0 commit comments