Skip to content

Commit 8b798a4

Browse files
Automatically try to clean up fixture repos after each test run.
And only delay cleanup if directories can't be deleted eagerly.
1 parent de3c320 commit 8b798a4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

test/test_helper.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
module Rugged
88
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+
1015
module FixtureRepo
1116
# Create a new, empty repository.
1217
def self.empty(*args)
@@ -66,11 +71,26 @@ def self.prepare(path)
6671
end
6772

6873
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 ||= []
7086
end
7187

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.
7291
def self.with_cleanup(repo, path)
7392
ObjectSpace.define_finalizer(repo, finalize_cleanup(path))
93+
self.directories << path
7494
repo
7595
end
7696
end

0 commit comments

Comments
 (0)