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
|
end
|
||||||
|
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
def initialize(path, mode = nil, perm = nil)
|
def initialize(path, mode = READ_ONLY, perm = nil)
|
||||||
|
check_mode(mode)
|
||||||
|
|
||||||
@path = path
|
@path = path
|
||||||
@mode = mode
|
@mode = mode
|
||||||
@file = FileSystem.find(path)
|
@file = FileSystem.find(path)
|
||||||
@ -146,5 +148,11 @@ module FakeFS
|
|||||||
def read_only?
|
def read_only?
|
||||||
@mode == READ_ONLY
|
@mode == READ_ONLY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_mode(mode)
|
||||||
|
if !MODES.include?(mode)
|
||||||
|
raise ArgumentError, "illegal access mode #{mode}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -106,6 +106,14 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
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
|
def test_can_read_files_once_written
|
||||||
path = '/path/to/file.txt'
|
path = '/path/to/file.txt'
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
|
Loading…
Reference in New Issue
Block a user