From a34f8e8beb5b4a603bdebf9934e9318ad81eeafc Mon Sep 17 00:00:00 2001 From: Jon Yurek Date: Tue, 29 Sep 2009 22:03:21 +0800 Subject: [PATCH] Implemented File.size --- lib/fakefs/file.rb | 4 ++++ test/fakefs_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb index 936ee93..7a1f9b3 100644 --- a/lib/fakefs/file.rb +++ b/lib/fakefs/file.rb @@ -18,6 +18,10 @@ module FakeFS alias_method :exists?, :exist? end + def self.size(path) + read(path).length + end + def self.const_missing(name) RealFile.const_get(name) end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 20550c7..0ba1f46 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -113,6 +113,14 @@ class FakeFSTest < Test::Unit::TestCase assert_equal 'Yada Yada', File.read(path) end + def test_can_get_size_of_files + path = '/path/to/file.txt' + File.open(path, 'w') do |f| + f << 'Yada Yada' + end + assert_equal 9, File.size(path) + end + def test_can_read_with_File_readlines path = '/path/to/file.txt' File.open(path, 'w') do |f|