aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_weakref.rb
blob: 97274c1f3f87a362b6befb4b1bc6e95b16bc357c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'test/unit'
require 'weakref'

class TestWeakRef < Test::Unit::TestCase
  def make_weakref
    obj = Object.new
    return WeakRef.new(obj), obj.to_s
  end

  def test_ref
    weak, str = make_weakref
    assert_equal(str, weak.to_s)
  end

  def test_recycled
    weak, str = make_weakref
    assert_nothing_raised(WeakRef::RefError) {weak.to_s}
    ObjectSpace.garbage_collect
    ObjectSpace.garbage_collect
    assert_raise(WeakRef::RefError) {weak.to_s}
  end
end