Skip to content

Commit 07227af

Browse files
Validating tmp_path before try to create the directory on #in_temp_dir (test helpe)
closes ruby-git#66
1 parent 2e459c2 commit 07227af

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tests/test_helper.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ def create_temp_repo(clone_path)
4343
end
4444

4545
def in_temp_dir(remove_after = true) # :yields: the temporary dir's path
46-
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
47-
tmp_path = File.join("/tmp/", filename)
46+
tmp_path = nil
47+
while tmp_path.nil? || File.directory?(tmp_path)
48+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
49+
tmp_path = File.join("/tmp/", filename)
50+
end
4851
FileUtils.mkdir(tmp_path)
4952
Dir.chdir tmp_path do
5053
yield tmp_path

0 commit comments

Comments
 (0)