aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-01 13:54:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-01 13:54:01 +0000
commit5e02a28a8b5e6defca76c4f3ee76bc48f0ce67b2 (patch)
tree10a108ea86dc514019b01f42351998119464ba01
parent9ad152e55580b497cbba4c7a15d20cba8e3ef1f5 (diff)
downloadruby-5e02a28a8b5e6defca76c4f3ee76bc48f0ce67b2.tar.gz
* lib/tempfile.rb (Tempfile#size): stat by path name when it is
closed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rwxr-xr-xlib/tempfile.rb2
-rw-r--r--test/test_tempfile.rb16
3 files changed, 14 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 8b833b6f86..cd388fe082 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Sat May 1 22:41:05 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat May 1 22:53:57 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/tempfile.rb (Tempfile#size): stat by path name when it is
+ closed.
* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert):
keep the first trace.
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 79dd5cc02c..c45865d7a3 100755
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -255,6 +255,8 @@ class Tempfile < DelegateClass(File)
if @tmpfile
@tmpfile.flush
@tmpfile.stat.size
+ elsif @tmpname
+ File.size(@tmpname)
else
0
end
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index e15d3f6a0c..cd7b80ddb4 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -153,7 +153,7 @@ class TestTempfile < Test::Unit::TestCase
end
def test_finalizer_does_not_unlink_if_already_unlinked
- assert_in_out_err('-rtempfile', <<-'EOS') do |(filename), (error)|
+ assert_in_out_err('-rtempfile', <<-'EOS') do |(filename,), (error,)|
file = Tempfile.new('foo')
path = file.path
puts path
@@ -165,7 +165,7 @@ File.open(path, "w").close
assert_nil error
end
- assert_in_out_err('-rtempfile', <<-'EOS') do |(filename), (error)|
+ assert_in_out_err('-rtempfile', <<-'EOS') do |(filename,), (error,)|
file = Tempfile.new('foo')
path = file.path
file.unlink
@@ -191,11 +191,11 @@ File.open(path, "w").close
t = tempfile("foo")
t.write("hello")
t.close
- assert 5, File.size(t.path)
+ assert_equal 5, File.size(t.path)
end
def test_tempfile_is_unlinked_when_ruby_exits
- assert_in_out_err('-rtempfile', <<-'EOS') do |(filename), (error)|
+ assert_in_out_err('-rtempfile', <<-'EOS') do |(filename,), (error,)|
puts Tempfile.new('foo').path
EOS
assert !File.exist?(filename)
@@ -205,16 +205,16 @@ puts Tempfile.new('foo').path
def test_size_flushes_buffer_before_determining_file_size
t = tempfile("foo")
t.write("hello")
- assert 0, File.size(t.path)
- assert 5, t.size
- assert 5, File.size(t.path)
+ assert_equal 0, File.size(t.path)
+ assert_equal 5, t.size
+ assert_equal 5, File.size(t.path)
end
def test_size_works_if_file_is_closed
t = tempfile("foo")
t.write("hello")
t.close
- assert 5, t.size
+ assert_equal 5, t.size
end
def test_concurrency