Raise an Errno::ENOENT error when opening a file which does not exist
This commit is contained in:
parent
a8245db145
commit
2881614123
@ -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
|
||||
|
@ -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|
|
||||
|
Loading…
Reference in New Issue
Block a user