Raise an Errno::ENOENT error when opening a file which does not exist

This commit is contained in:
Scott Taylor 2009-09-30 03:03:21 -04:00
parent a8245db145
commit 2881614123
2 changed files with 14 additions and 0 deletions

View File

@ -107,6 +107,8 @@ module FakeFS
@mode = mode
@file = FileSystem.find(path)
@open = true
check_file_existence! if read_only?
end
def close
@ -145,6 +147,12 @@ module FakeFS
private
def check_file_existence!
unless @file
raise Errno::ENOENT, "No such file or directory - #{@file}"
end
end
def read_only?
@mode == READ_ONLY
end

View File

@ -114,6 +114,12 @@ class FakeFSTest < Test::Unit::TestCase
end
end
def test_raises_error_when_cannot_find_file_in_read_mode
assert_raises(Errno::ENOENT) do
File.open("does_not_exist", "r")
end
end
def test_can_read_files_once_written
path = '/path/to/file.txt'
File.open(path, 'w') do |f|