FileUtils#rm and File#delete should raise Errno::ENOENT when any file

does not exist (Closes #70)
This commit is contained in:
Scott Taylor 2011-09-05 17:34:09 -04:00
parent 47b34075a8
commit 4da1d58d66
3 changed files with 8 additions and 9 deletions

View File

@ -68,6 +68,7 @@ module FakeFS
def delete(path) def delete(path)
if node = FileSystem.find(path) if node = FileSystem.find(path)
node.delete node.delete
true
end end
end end

View File

@ -30,7 +30,7 @@ module FakeFS
def rm(list, options = {}) def rm(list, options = {})
Array(list).each do |path| Array(list).each do |path|
FileSystem.delete(path) FileSystem.delete(path) or raise Errno::ENOENT.new(path)
end end
end end

View File

@ -65,6 +65,12 @@ class FakeFSTest < Test::Unit::TestCase
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir'] assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
end end
def test_unlink_errors_on_file_not_found
assert_raise Errno::ENOENT do
FileUtils.rm("/foo")
end
end
def test_can_delete_directories def test_can_delete_directories
FileUtils.mkdir_p("/path/to/dir") FileUtils.mkdir_p("/path/to/dir")
FileUtils.rmdir("/path/to/dir") FileUtils.rmdir("/path/to/dir")
@ -1582,14 +1588,6 @@ class FakeFSTest < Test::Unit::TestCase
end end
end end
def test_delete_does_not_raise_error_when_second_file_does_not_exist
FileUtils.touch("/foo")
assert_nothing_raised do
File.delete("/foo", "/bar")
end
end
def test_unlink_is_alias_for_delete def test_unlink_is_alias_for_delete
assert_equal File.method(:unlink), File.method(:delete) assert_equal File.method(:unlink), File.method(:delete)
end end