Created
March 5, 2010 17:01
-
-
Save vvs/322917 to your computer and use it in GitHub Desktop.
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
require 'tempfile' | |
require 'java' if defined?(JRUBY_VERSION) | |
require 'test/unit' | |
require 'fileutils' | |
class TestTempfilesCleanUp < Test::Unit::TestCase | |
def setup | |
@tmpdir = "tmp_#{$$}" | |
Dir.mkdir @tmpdir rescue nil | |
end | |
def teardown | |
FileUtils.rm_f @tmpdir | |
end | |
def test_cleanup | |
path = Tempfile.open('blah', @tmpdir).path | |
# fails on MRI without this!!! :) | |
p path | |
# test that it's there | |
assert File.exist?(path), 'file was not created' | |
# fails on MRI without this!!! | |
10.times { Tempfile.open('blah', @tmpdir) } | |
100.times do | |
if defined?(JRUBY_VERSION) | |
java.lang.System.gc | |
else | |
GC.start | |
end | |
end | |
# test that the file is gone | |
assert !File.exist?(path), 'file was not cleaned up' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment