Improved error handling for Dir.delete and Dir.entries

This better matches the behavior of Ruby 1.8 and 1.9

(Closes #91)
This commit is contained in:
Ryan McGeary 2011-07-27 21:47:11 -04:00 committed by Scott Taylor
parent 14367140a3
commit c24b338a2e
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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' ]