Skip to content

Instantly share code, notes, and snippets.

@vvs
Created March 5, 2010 17:01
Show Gist options
  • Save vvs/322917 to your computer and use it in GitHub Desktop.
Save vvs/322917 to your computer and use it in GitHub Desktop.
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