Adding File.size? too

This commit is contained in:
Nick Quaranto 2009-09-29 11:08:22 -04:00 committed by Chris Wanstrath
parent 166ff444d9
commit e591d3b2d3
2 changed files with 21 additions and 0 deletions

View File

@ -50,6 +50,10 @@ module FakeFS
read(path).length read(path).length
end end
def self.size?(path)
exists?(path) && !size(path).zero?
end
def self.const_missing(name) def self.const_missing(name)
RealFile.const_get(name) RealFile.const_get(name)
end end

View File

@ -208,6 +208,23 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal 9, File.size(path) assert_equal 9, File.size(path)
end end
def test_can_check_if_file_has_size?
path = '/path/to/file.txt'
File.open(path, 'w') do |f|
f << 'Yada Yada'
end
assert File.size?(path)
assert ! File.size?("/path/to/other.txt")
end
def test_can_check_size?_of_empty_file
path = '/path/to/file.txt'
File.open(path, 'w') do |f|
f << ''
end
assert ! File.size?("/path/to/file.txt")
end
def test_can_read_with_File_readlines def test_can_read_with_File_readlines
path = '/path/to/file.txt' path = '/path/to/file.txt'
File.open(path, 'w') do |f| File.open(path, 'w') do |f|