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:
parent
14367140a3
commit
c24b338a2e
@ -65,12 +65,13 @@ module FakeFS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.delete(string)
|
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)
|
FileSystem.delete(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.entries(dirname)
|
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) }
|
Dir.new(dirname).map { |file| File.basename(file) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1211,11 +1211,17 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
FileUtils.touch("/this/path/should/be/here/#{f}")
|
FileUtils.touch("/this/path/should/be/here/#{f}")
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_raises(SystemCallError) do
|
assert_raises(Errno::ENOTEMPTY) do
|
||||||
Dir.delete('/this/path/should/be/here')
|
Dir.delete('/this/path/should/be/here')
|
||||||
end
|
end
|
||||||
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
|
def test_directory_entries
|
||||||
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
|
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) }
|
test.each { |t| assert yielded.include?(t) }
|
||||||
end
|
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
|
def test_directory_foreach
|
||||||
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
|
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user