raise Errno::EEXIST when Dir.mkdir is called with an existing directory. Closes #21.

This commit is contained in:
Scott Taylor 2009-11-24 04:08:14 -05:00
parent ceffec3023
commit bdb3fa4ac0
2 changed files with 9 additions and 0 deletions

View File

@ -86,6 +86,7 @@ module FakeFS
parent = string.split('/')
parent.pop
raise Errno::ENOENT, "No such file or directory - #{string}" unless parent.join == "" || FileSystem.find(parent.join('/'))
raise Errno::EEXIST, "File exists - #{string}" if File.exists?(string)
FileUtils.mkdir_p(string)
end

View File

@ -1102,6 +1102,14 @@ class FakeFSTest < Test::Unit::TestCase
end
end
def test_mkdir_raises_error_if_already_created
Dir.mkdir "foo"
assert_raises(Errno::EEXIST) do
Dir.mkdir "foo"
end
end
def test_directory_open
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]