diff --git a/test/ruby/test_objectspace.rb b/test/ruby/test_objectspace.rb index a57c7ea1d1..cb17d03417 100644 --- a/test/ruby/test_objectspace.rb +++ b/test/ruby/test_objectspace.rb @@ -85,6 +85,30 @@ End end def test_each_object + klass = Class.new + new_obj = klass.new + + found = [] + count = ObjectSpace.each_object(klass) do |obj| + found << obj + end + assert_equal(1, count) + assert_equal(1, found.size) + assert_same(new_obj, found[0]) + end + + def test_each_object_enumerator + klass = Class.new + new_obj = klass.new + + found = [] + counter = ObjectSpace.each_object(klass) + assert_equal(1, counter.each {|obj| found << obj}) + assert_equal(1, found.size) + assert_same(new_obj, found[0]) + end + + def test_each_object_no_gabage assert_separately([], <<-End) GC.disable eval('begin; 1.times{}; rescue; ensure; end')