Skip to content

Commit

Permalink
Add File.zero?
Browse files Browse the repository at this point in the history
  • Loading branch information
emilsoman committed Mar 11, 2013
1 parent 89a7e39 commit 025b7db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/fakefs/file.rb
Expand Up @@ -100,6 +100,14 @@ def self.size?(path)
end
end

def self.zero?(path)
if exists?(path) and size(path) == 0
true
else
false
end
end

def self.const_missing(name)
RealFile.const_get(name)
end
Expand Down
21 changes: 21 additions & 0 deletions test/fakefs_test.rb
Expand Up @@ -492,6 +492,27 @@ def test_can_check_size_of_empty_file
assert_nil File.size?("file.txt")
end

def test_zero_on_empty_file
path = 'file.txt'
File.open(path, 'w') do |f|
f << ''
end
assert_equal true, File.zero?(path)
end

def test_zero_on_non_empty_file
path = 'file.txt'
File.open(path, 'w') do |f|
f << 'Not empty'
end
assert_equal false, File.zero?(path)
end

def test_zero_on_non_existent_file
path = 'file_does_not_exist.txt'
assert_equal false, File.zero?(path)
end

def test_raises_error_on_mtime_if_file_does_not_exist
assert_raise Errno::ENOENT do
File.mtime('/path/to/file.txt')
Expand Down

0 comments on commit 025b7db

Please sign in to comment.