From bdb3fa4ac07c09143a97db73cccb47155d298aca Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 24 Nov 2009 04:08:14 -0500 Subject: [PATCH] raise Errno::EEXIST when Dir.mkdir is called with an existing directory. Closes #21. --- lib/fakefs/dir.rb | 1 + test/fakefs_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/fakefs/dir.rb b/lib/fakefs/dir.rb index e241661..c407928 100644 --- a/lib/fakefs/dir.rb +++ b/lib/fakefs/dir.rb @@ -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 diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 3f0e6ab..456ad70 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -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' ]