From 82db05e85d1a486fbdb671af4b1d93085e515c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Sun, 3 Oct 2010 18:02:17 +0200 Subject: [PATCH] Implemented File.autoclose?, File.autoclose=, File.fdatasync and File.size which are new on ruby-1.9.2 --- Rakefile | 1 + lib/fakefs/file.rb | 17 ++++++++++++++++- test/fakefs_test.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index db71ab8..f33d223 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +$LOAD_PATH.unshift File.join(File.dirname(__FILE__)) $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'test') desc "Run tests" diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb index b347867..31676a2 100644 --- a/lib/fakefs/file.rb +++ b/lib/fakefs/file.rb @@ -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! diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index fdb0309..43c216e 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -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