Raise an error when opening a file which does not exist in read-write ('r+') mode

This commit is contained in:
Scott Taylor 2009-09-30 03:13:58 -04:00
parent 2881614123
commit 17e2e47027
2 changed files with 15 additions and 1 deletions

View File

@ -108,7 +108,7 @@ module FakeFS
@file = FileSystem.find(path)
@open = true
check_file_existence! if read_only?
check_file_existence! if !file_creation_mode?
end
def close
@ -157,6 +157,14 @@ module FakeFS
@mode == READ_ONLY
end
def file_creation_modes
MODES - [READ_ONLY, READ_WRITE]
end
def file_creation_mode?
file_creation_modes.include?(@mode)
end
def check_mode(mode)
if !MODES.include?(mode)
raise ArgumentError, "illegal access mode #{mode}"

View File

@ -120,6 +120,12 @@ class FakeFSTest < Test::Unit::TestCase
end
end
def test_raises_error_when_cannot_find_file_in_read_write_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|