ensure File.read raises the correct error

This commit is contained in:
Chris Wanstrath 2009-06-03 17:47:10 -07:00
parent 8aba1ad6a5
commit e051533cd4
2 changed files with 18 additions and 4 deletions

View File

@ -126,7 +126,12 @@ module FakeFS
end
def self.read(path)
new(path).read
file = new(path)
if file.exists?
file.read
else
raise Errno::ENOENT
end
end
def self.readlines(path)
@ -144,6 +149,10 @@ module FakeFS
@file.content
end
def exists?
@file
end
def puts(content)
write(content + "\n")
end

View File

@ -41,7 +41,7 @@ class FakeFSTest < Test::Unit::TestCase
FileUtils.ln_s path, sympath = '/sympath'
assert File.directory?(sympath)
end
def test_doesnt_overwrite_existing_directories
FileUtils.mkdir_p(path = "/path/to/dir")
assert File.exists?(path)
@ -108,6 +108,12 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal "Yatta!", File.new(path).read
end
def test_file_read_errors_appropriately
assert_raise Errno::ENOENT do
File.read('anything')
end
end
def test_knows_files_are_files
path = '/path/to/file.txt'
File.open(path, 'w') do |f|
@ -126,7 +132,7 @@ class FakeFSTest < Test::Unit::TestCase
assert File.file?(sympath)
end
def test_can_chown_files
good = 'file.txt'
bad = 'nofile.txt'
@ -393,7 +399,6 @@ class FakeFSTest < Test::Unit::TestCase
File.open('subdir/nother','w'){|f| f.write 'works' }
FileUtils.ln_s 'subdir', 'new'
assert_equal 'works', File.open('new/nother'){|f| f.read }
end
def here(fname)