ensure File.read raises the correct error
This commit is contained in:
parent
8aba1ad6a5
commit
e051533cd4
@ -126,7 +126,12 @@ module FakeFS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.read(path)
|
def self.read(path)
|
||||||
new(path).read
|
file = new(path)
|
||||||
|
if file.exists?
|
||||||
|
file.read
|
||||||
|
else
|
||||||
|
raise Errno::ENOENT
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.readlines(path)
|
def self.readlines(path)
|
||||||
@ -144,6 +149,10 @@ module FakeFS
|
|||||||
@file.content
|
@file.content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exists?
|
||||||
|
@file
|
||||||
|
end
|
||||||
|
|
||||||
def puts(content)
|
def puts(content)
|
||||||
write(content + "\n")
|
write(content + "\n")
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
FileUtils.ln_s path, sympath = '/sympath'
|
FileUtils.ln_s path, sympath = '/sympath'
|
||||||
assert File.directory?(sympath)
|
assert File.directory?(sympath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_doesnt_overwrite_existing_directories
|
def test_doesnt_overwrite_existing_directories
|
||||||
FileUtils.mkdir_p(path = "/path/to/dir")
|
FileUtils.mkdir_p(path = "/path/to/dir")
|
||||||
assert File.exists?(path)
|
assert File.exists?(path)
|
||||||
@ -108,6 +108,12 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
assert_equal "Yatta!", File.new(path).read
|
assert_equal "Yatta!", File.new(path).read
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_file_read_errors_appropriately
|
||||||
|
assert_raise Errno::ENOENT do
|
||||||
|
File.read('anything')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_knows_files_are_files
|
def test_knows_files_are_files
|
||||||
path = '/path/to/file.txt'
|
path = '/path/to/file.txt'
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
@ -126,7 +132,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert File.file?(sympath)
|
assert File.file?(sympath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_can_chown_files
|
def test_can_chown_files
|
||||||
good = 'file.txt'
|
good = 'file.txt'
|
||||||
bad = 'nofile.txt'
|
bad = 'nofile.txt'
|
||||||
@ -393,7 +399,6 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
File.open('subdir/nother','w'){|f| f.write 'works' }
|
File.open('subdir/nother','w'){|f| f.write 'works' }
|
||||||
FileUtils.ln_s 'subdir', 'new'
|
FileUtils.ln_s 'subdir', 'new'
|
||||||
assert_equal 'works', File.open('new/nother'){|f| f.read }
|
assert_equal 'works', File.open('new/nother'){|f| f.read }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def here(fname)
|
def here(fname)
|
||||||
|
Loading…
Reference in New Issue
Block a user