aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/garbage_collection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/testing/garbage_collection.rb')
-rw-r--r--activesupport/lib/active_support/testing/garbage_collection.rb19
1 files changed, 19 insertions, 0 deletions
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