Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scrub instance variables from test cases on teardown
this prevents test state from accumulating, resulting in leaked objects and slow tests due to overactive GC.
- Loading branch information
Showing
4 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
activesupport/lib/active_support/testing/garbage_collection.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters