Implemented File.autoclose?, File.autoclose=, File.fdatasync and File.size which are new on ruby-1.9.2

This commit is contained in:
Víctor Martínez 2010-10-03 18:02:17 +02:00 committed by Scott Taylor
parent 6759a99780
commit 82db05e85d
3 changed files with 43 additions and 1 deletions

View File

@ -1,3 +1,4 @@
$LOAD_PATH.unshift File.join(File.dirname(__FILE__))
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'test')
desc "Run tests"

View File

@ -228,6 +228,7 @@ module FakeFS
@path = path
@mode = mode
@file = FileSystem.find(path)
@autoclose = true
check_modes!
@ -310,7 +311,7 @@ module FakeFS
self.class.mtime(@path)
end
if RUBY_VERSION.to_f >= 1.9
if RUBY_VERSION >= "1.9"
def binmode?
raise NotImplementedError
end
@ -328,6 +329,20 @@ module FakeFS
end
end
if RUBY_VERSION >= "1.9.2"
attr_writer :autoclose
def autoclose?
@autoclose
end
alias_method :fdatasync, :flush
def size
File.size(@path)
end
end
private
def check_modes!

View File

@ -1459,4 +1459,30 @@ class FakeFSTest < Test::Unit::TestCase
def here(fname)
RealFile.expand_path(File.join(RealFile.dirname(__FILE__), fname))
end
if RUBY_VERSION >= "1.9.2"
def test_file_size
File.open("foo", 'w') do |f|
f << 'Yada Yada'
assert_equal 9, f.size
end
end
def test_fdatasync
File.open("foo", 'w') do |f|
f << 'Yada Yada'
assert_nothing_raised do
f.fdatasync
end
end
end
def test_autoclose
File.open("foo", 'w') do |f|
assert_equal true, f.autoclose?
f.autoclose = false
assert_equal false, f.autoclose?
end
end
end
end