[前][次][番号順一覧][スレッド一覧]

ruby-changes:34067

From: akr <ko1@a...>
Date: Mon, 26 May 2014 23:45:55 +0900 (JST)
Subject: [ruby-changes:34067] akr:r46148 (trunk): Use Tempfile.create instead of Tempfile.new.

akr	2014-05-26 23:45:51 +0900 (Mon, 26 May 2014)

  New Revision: 46148

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46148

  Log:
    Use Tempfile.create instead of Tempfile.new.

  Modified files:
    trunk/test/ruby/test_file.rb
Index: test/ruby/test_file.rb
===================================================================
--- test/ruby/test_file.rb	(revision 46147)
+++ test/ruby/test_file.rb	(revision 46148)
@@ -313,32 +313,31 @@ class TestFile < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file.rb#L313
 
   def test_stat
     tb = Process.clock_gettime(Process::CLOCK_REALTIME)
-    file = Tempfile.new("stat")
-    tb = (tb + Process.clock_gettime(Process::CLOCK_REALTIME)) / 2
-    file.close
-    path = file.path
+    Tempfile.create("stat") {|file|
+      tb = (tb + Process.clock_gettime(Process::CLOCK_REALTIME)) / 2
+      file.close
+      path = file.path
 
-    t0 = Process.clock_gettime(Process::CLOCK_REALTIME)
-    File.write(path, "foo")
-    sleep 2
-    File.write(path, "bar")
-    sleep 2
-    File.chmod(0644, path)
-    sleep 2
-    File.read(path)
+      t0 = Process.clock_gettime(Process::CLOCK_REALTIME)
+      File.write(path, "foo")
+      sleep 2
+      File.write(path, "bar")
+      sleep 2
+      File.chmod(0644, path)
+      sleep 2
+      File.read(path)
 
-    delta = 1
-    stat = File.stat(path)
-    assert_in_delta tb,   stat.birthtime.to_f, delta
-    assert_in_delta t0+2, stat.mtime.to_f, delta
-    if stat.birthtime != stat.ctime
-      assert_in_delta t0+4, stat.ctime.to_f, delta
-    end
-    skip "Windows delays updating atime" if /mswin|mingw/ =~ RUBY_PLATFORM
-    assert_in_delta t0+6, stat.atime.to_f, delta
+      delta = 1
+      stat = File.stat(path)
+      assert_in_delta tb,   stat.birthtime.to_f, delta
+      assert_in_delta t0+2, stat.mtime.to_f, delta
+      if stat.birthtime != stat.ctime
+        assert_in_delta t0+4, stat.ctime.to_f, delta
+      end
+      skip "Windows delays updating atime" if /mswin|mingw/ =~ RUBY_PLATFORM
+      assert_in_delta t0+6, stat.atime.to_f, delta
+    }
   rescue NotImplementedError
-  ensure
-    file.close!
   end
 
   def test_chmod_m17n

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]