Issue #8768 has been updated by nobu (Nobuyoshi Nakada).


I couldn't let the test fail with the current code, but succeeded by setting $DEBUG at the end.

  def test_tempfile_finalizer_does_not_run_if_unlinked
    args = %w(--disable-gems -rtempfile)
    assert_in_out_err(args, <<-'EOS') do |(filename), (error)|
    tmp = Tempfile.new('foo')
    puts tmp.path
    tmp.unlink
    $DEBUG = true
    EOS
      assert_file.not_exist?(filename)
      assert_nil error, "we used to get a confusing 'removing ...done' here"
    end
  end

----------------------------------------
Bug #8768: [PATCH] tempfile: undefine finalizer on unlink
https://bugs.ruby-lang.org/issues/8768#change-41866

Author: normalperson (Eric Wong)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: lib
Target version: current: 2.1.0
ruby -v: ruby 2.1.0dev (2013-08-10 trunk 42491) [x86_64-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


* lib/tempfile.rb (Tempfile#unlink): undefine finalizer
    
running the finalizer on an unlinked Tempfile leads to a confusing
"removing ...done" message when using --debug.  We can rely on
normal GC to close.  rb_io_fptr_finalize will take care of closing
the descriptor without the extra finalizer for Tempfile.


-- 
http://bugs.ruby-lang.org/