From 4da1d58d66a729c2e40947c2212109cbbde39b16 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 5 Sep 2011 17:34:09 -0400 Subject: [PATCH] FileUtils#rm and File#delete should raise Errno::ENOENT when any file does not exist (Closes #70) --- lib/fakefs/file_system.rb | 1 + lib/fakefs/fileutils.rb | 2 +- test/fakefs_test.rb | 14 ++++++-------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/fakefs/file_system.rb b/lib/fakefs/file_system.rb index 2367244..1c6f851 100644 --- a/lib/fakefs/file_system.rb +++ b/lib/fakefs/file_system.rb @@ -68,6 +68,7 @@ module FakeFS def delete(path) if node = FileSystem.find(path) node.delete + true end end diff --git a/lib/fakefs/fileutils.rb b/lib/fakefs/fileutils.rb index d5a904a..81ff2d7 100644 --- a/lib/fakefs/fileutils.rb +++ b/lib/fakefs/fileutils.rb @@ -30,7 +30,7 @@ module FakeFS def rm(list, options = {}) Array(list).each do |path| - FileSystem.delete(path) + FileSystem.delete(path) or raise Errno::ENOENT.new(path) end end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index bcb487a..eda6ea2 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -65,6 +65,12 @@ class FakeFSTest < Test::Unit::TestCase assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir'] end + def test_unlink_errors_on_file_not_found + assert_raise Errno::ENOENT do + FileUtils.rm("/foo") + end + end + def test_can_delete_directories FileUtils.mkdir_p("/path/to/dir") FileUtils.rmdir("/path/to/dir") @@ -1582,14 +1588,6 @@ class FakeFSTest < Test::Unit::TestCase 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 assert_equal File.method(:unlink), File.method(:delete) end