aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/test_case.rb2
-rw-r--r--activesupport/lib/active_support/testing/garbage_collection.rb19
2 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index fb52fc7083..a7053a1134 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -6,6 +6,7 @@ require 'active_support/testing/declarative'
require 'active_support/testing/pending'
require 'active_support/testing/isolation'
require 'active_support/core_ext/kernel/reporting'
+require 'active_support/testing/garbage_collection'
begin
silence_warnings { require 'mocha' }
@@ -37,5 +38,6 @@ module ActiveSupport
include ActiveSupport::Testing::Deprecation
include ActiveSupport::Testing::Pending
extend ActiveSupport::Testing::Declarative
+ include ActiveSupport::Testing::GarbageCollection
end
end
diff --git a/activesupport/lib/active_support/testing/garbage_collection.rb b/activesupport/lib/active_support/testing/garbage_collection.rb
new file mode 100644
index 0000000000..7bf9fbafa6
--- /dev/null
+++ b/activesupport/lib/active_support/testing/garbage_collection.rb
@@ -0,0 +1,19 @@
+module ActiveSupport
+ module Testing
+ module GarbageCollection
+ def self.included(base)
+ base.teardown :scrub_leftover_instance_variables
+ end
+
+ private
+
+ RESERVED_INSTANCE_VARIABLES = %w(@test_passed @passed @method_name @__name__ @_result).map(&:to_sym)
+
+ def scrub_leftover_instance_variables
+ (instance_variables.map(&:to_sym) - RESERVED_INSTANCE_VARIABLES).each do |var|
+ remove_instance_variable(var)
+ end
+ end
+ end
+ end
+end