Guest User

Untitled

a guest
May 20th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1.  
  2.  
  3.  
  4. require 'tempfile'
  5. require 'java' if defined?(JRUBY_VERSION)
  6. require 'test/unit'
  7. require 'fileutils'
  8.  
  9. class FileOpener
  10. def initialize(tmp)
  11. path = Tempfile.open('blah', tmp).path
  12.  
  13. # fails on MRI without this!!! :)
  14. p path
  15. end
  16. end
  17.  
  18.  
  19. class TestTempfilesCleanUp < Test::Unit::TestCase
  20.  
  21. def setup
  22. @tmpdir = "tmp_#{$$}"
  23. Dir.mkdir @tmpdir rescue nil
  24. end
  25.  
  26. def teardown
  27. FileUtils.rm_f @tmpdir
  28. end
  29.  
  30.  
  31. def test_open_files
  32. loop do
  33. FileOpener.new(@tmpdir)
  34. if defined?(JRUBY_VERSION)
  35. java.lang.System.gc
  36. else
  37. GC.start
  38. end
  39. end
  40. end
  41.  
  42. end
Add Comment
Please, Sign In to add comment