Raise an error when giving File.open an illegal access mode. Set default mode for File.open to READ_ONLY
This commit is contained in:
parent
6068034c29
commit
a8245db145
@ -100,7 +100,9 @@ module FakeFS
|
||||
end
|
||||
|
||||
attr_reader :path
|
||||
def initialize(path, mode = nil, perm = nil)
|
||||
def initialize(path, mode = READ_ONLY, perm = nil)
|
||||
check_mode(mode)
|
||||
|
||||
@path = path
|
||||
@mode = mode
|
||||
@file = FileSystem.find(path)
|
||||
@ -146,5 +148,11 @@ module FakeFS
|
||||
def read_only?
|
||||
@mode == READ_ONLY
|
||||
end
|
||||
|
||||
def check_mode(mode)
|
||||
if !MODES.include?(mode)
|
||||
raise ArgumentError, "illegal access mode #{mode}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -106,6 +106,14 @@ class FakeFSTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_file_opens_in_invalid_mode
|
||||
FileUtils.touch("foo")
|
||||
|
||||
assert_raises(ArgumentError) do
|
||||
File.open("foo", "an_illegal_mode")
|
||||
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