1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Description: pre-create instance variables before run() so they survive Test::Unit >= 3.6.8 ivar cleanup
The test suite in ruby-test-unit-context relies on instance variables set by
setup/teardown hooks remaining accessible after the test case has finished
running. Since test-unit 3.6.8 (commit roughly equivalent to upstream PR #235),
Test::Unit::TestCase#run performs an explicit cleanup of instance variables
that were not present at the beginning of the run method (for better GC
behavior). This causes all the meta-test assertions in hooks_test.rb to see
nil instead of the expected values.
Author: Simon Quigley <tsimonq2@debian.org>
Origin: vendor
Last-Update: 2026-02-22
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/test/test/unit/context/hooks_test.rb
+++ b/test/test/unit/context/hooks_test.rb
@@ -117,6 +117,7 @@ module Test::Unit::Context
setup do
result = Test::Unit::TestResult.new
@test = SAMPLE_TEST1.new("test: foo")
+ %i[@superclass_before_each_var @inherited_before_each_var @inherited_before_each_var_2 @after_each_var @superclass_after_each_var @inherited_after_each_var @ivar @one @two].each { |v| @test.instance_variable_set(v, nil) }
@test.default_run(result) { |inherited_after_each_var, v| }
verify_result_passed! result
end
@@ -161,6 +162,7 @@ module Test::Unit::Context
setup do
@result = Test::Unit::TestResult.new
@test = SAMPLE_TEST2.new("test: foo")
+ %i[@superclass_before_each_var @inherited_before_each_var @inherited_before_each_var_2 @after_each_var @superclass_after_each_var @inherited_after_each_var @ivar @one @two].each { |v| @test.instance_variable_set(v, nil) }
@test.default_run(@result) { |inherited_after_each_var, v| }
end
@@ -219,6 +221,7 @@ module Test::Unit::Context
#SAMPLE_TEST3.teardown { @two = 10 }
@test = SAMPLE_TEST3.new("test: foo")
+ %i[@superclass_before_each_var @inherited_before_each_var @inherited_before_each_var_2 @after_each_var @superclass_after_each_var @inherited_after_each_var @ivar @one @two].each { |v| @test.instance_variable_set(v, nil) }
@test.class.setup do
@one = 1
@@ -279,4 +282,4 @@ module Test::Unit::Context
end
-end
\ No newline at end of file
+end
|