File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
module Rugged
8
8
class TestCase < MiniTest ::Unit ::TestCase
9
- # Helper methods to
9
+ # Automatically clean up created fixture repos after each test run
10
+ def after_teardown
11
+ Rugged ::TestCase ::FixtureRepo . eager_teardown
12
+ super
13
+ end
14
+
10
15
module FixtureRepo
11
16
# Create a new, empty repository.
12
17
def self . empty ( *args )
@@ -66,11 +71,26 @@ def self.prepare(path)
66
71
end
67
72
68
73
def self . finalize_cleanup ( path )
69
- proc { FileUtils . remove_entry_secure ( path ) }
74
+ proc { FileUtils . remove_entry_secure ( path ) if File . exist? ( path ) }
75
+ end
76
+
77
+ # Try to eagerly delete directories containing fixture repos.
78
+ def self . eager_teardown
79
+ while path = self . directories . pop
80
+ FileUtils . remove_entry_secure ( path ) rescue nil
81
+ end
82
+ end
83
+
84
+ def self . directories
85
+ @directories ||= [ ]
70
86
end
71
87
88
+ # Schedule the given +path+ to be deleted, either when
89
+ # +FixtureRepo.eager_teardown+ is called or when the given +repo+
90
+ # gets gc'ed.
72
91
def self . with_cleanup ( repo , path )
73
92
ObjectSpace . define_finalizer ( repo , finalize_cleanup ( path ) )
93
+ self . directories << path
74
94
repo
75
95
end
76
96
end
You can’t perform that action at this time.
0 commit comments