Skip to content

Instantly share code, notes, and snippets.

@soma
Created March 9, 2010 16:06
Show Gist options
  • Select an option

  • Save soma/326737 to your computer and use it in GitHub Desktop.

Select an option

Save soma/326737 to your computer and use it in GitHub Desktop.
require 'tempfile'
require 'java' if defined?(JRUBY_VERSION)
require 'test/unit'
require 'fileutils'
class FileOpener
def initialize(tmp)
path = Tempfile.open('blah', tmp).path
# fails on MRI without this!!! :)
p path
end
end
class TestTempfilesCleanUp < Test::Unit::TestCase
def setup
@tmpdir = "tmp_#{$$}"
Dir.mkdir @tmpdir rescue nil
end
def teardown
FileUtils.rm_f @tmpdir
end
def test_open_files
loop do
FileOpener.new(@tmpdir)
if defined?(JRUBY_VERSION)
java.lang.System.gc
else
GC.start
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment