diff --git a/lib/fakefs/dir.rb b/lib/fakefs/dir.rb index b2d84fd..64ac8fd 100644 --- a/lib/fakefs/dir.rb +++ b/lib/fakefs/dir.rb @@ -65,12 +65,13 @@ module FakeFS end def self.delete(string) - raise SystemCallError, "No such file or directory - #{string}" unless FileSystem.find(string).values.empty? + raise Errno::ENOENT, "No such file or directory - #{string}" unless FileSystem.find(string) + raise Errno::ENOTEMPTY, "Directory not empty - #{string}" unless FileSystem.find(string).values.empty? FileSystem.delete(string) end def self.entries(dirname) - raise SystemCallError, dirname unless FileSystem.find(dirname) + raise Errno::ENOENT, "No such file or directory - #{dirname}" unless FileSystem.find(dirname) Dir.new(dirname).map { |file| File.basename(file) } end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 732c1d2..80b4252 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -1211,11 +1211,17 @@ class FakeFSTest < Test::Unit::TestCase FileUtils.touch("/this/path/should/be/here/#{f}") end - assert_raises(SystemCallError) do + assert_raises(Errno::ENOTEMPTY) do Dir.delete('/this/path/should/be/here') end end + def test_directory_class_delete_does_not_work_if_dir_path_cannot_be_found + assert_raises(Errno::ENOENT) do + Dir.delete('/this/path/should/not/be/here') + end + end + def test_directory_entries test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ] @@ -1244,6 +1250,12 @@ class FakeFSTest < Test::Unit::TestCase test.each { |t| assert yielded.include?(t) } end + def test_directory_entries_does_not_work_if_dir_path_cannot_be_found + assert_raises(Errno::ENOENT) do + Dir.delete('/this/path/should/not/be/here') + end + end + def test_directory_foreach test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]