Raise an error when opening a file which does not exist in read-write ('r+') mode
This commit is contained in:
parent
2881614123
commit
17e2e47027
@ -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}"
|
||||
|
@ -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|
|
||||
|
Loading…
Reference in New Issue
Block a user