Skip to content

Commit 483ef3a

Browse files
committed
Test test_remove_instance_variable_re_embed separately
Shape tree pollution could cause this test to flake.
1 parent f42535f commit 483ef3a

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

test/ruby/test_object.rb

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -356,40 +356,41 @@ def test_remove_instance_variable
356356
end
357357

358358
def test_remove_instance_variable_re_embed
359-
require "objspace"
359+
assert_separately(%w[-robjspace], "#{<<~"begin;"}\n#{<<~'end;'}")
360+
begin;
361+
c = Class.new do
362+
attr_reader :a, :b, :c
360363
361-
c = Class.new do
362-
attr_reader :a, :b, :c
363-
364-
def initialize
365-
@a = nil
366-
@b = nil
367-
@c = nil
364+
def initialize
365+
@a = nil
366+
@b = nil
367+
@c = nil
368+
end
368369
end
369-
end
370370
371-
o1 = c.new
372-
o2 = c.new
373-
374-
o1.instance_variable_set(:@foo, 5)
375-
o1.instance_variable_set(:@a, 0)
376-
o1.instance_variable_set(:@b, 1)
377-
o1.instance_variable_set(:@c, 2)
378-
refute_includes ObjectSpace.dump(o1), '"embedded":true'
379-
o1.remove_instance_variable(:@foo)
380-
assert_includes ObjectSpace.dump(o1), '"embedded":true'
381-
382-
o2.instance_variable_set(:@a, 0)
383-
o2.instance_variable_set(:@b, 1)
384-
o2.instance_variable_set(:@c, 2)
385-
assert_includes ObjectSpace.dump(o2), '"embedded":true'
386-
387-
assert_equal(0, o1.a)
388-
assert_equal(1, o1.b)
389-
assert_equal(2, o1.c)
390-
assert_equal(0, o2.a)
391-
assert_equal(1, o2.b)
392-
assert_equal(2, o2.c)
371+
o1 = c.new
372+
o2 = c.new
373+
374+
o1.instance_variable_set(:@foo, 5)
375+
o1.instance_variable_set(:@a, 0)
376+
o1.instance_variable_set(:@b, 1)
377+
o1.instance_variable_set(:@c, 2)
378+
refute_includes ObjectSpace.dump(o1), '"embedded":true'
379+
o1.remove_instance_variable(:@foo)
380+
assert_includes ObjectSpace.dump(o1), '"embedded":true'
381+
382+
o2.instance_variable_set(:@a, 0)
383+
o2.instance_variable_set(:@b, 1)
384+
o2.instance_variable_set(:@c, 2)
385+
assert_includes ObjectSpace.dump(o2), '"embedded":true'
386+
387+
assert_equal(0, o1.a)
388+
assert_equal(1, o1.b)
389+
assert_equal(2, o1.c)
390+
assert_equal(0, o2.a)
391+
assert_equal(1, o2.b)
392+
assert_equal(2, o2.c)
393+
end;
393394
end
394395

395396
def test_convert_string

0 commit comments

Comments
 (0)