From d8aa9f38fc00477a776fc3aac8dd5b975846318a Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 29 May 2009 11:00:44 -0700 Subject: [PATCH] don't overwrite existing directories yet --- lib/fakefs.rb | 4 ++-- test/fakefs_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/fakefs.rb b/lib/fakefs.rb index ef1427c..d3892d4 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -43,7 +43,7 @@ module FakeFS end def self.exists?(path) - FileSystem.find(path) + FileSystem.find(path) || false end def self.directory?(path) @@ -152,7 +152,7 @@ module FakeFS object.name = parts.last object.parent = d - d[parts.last] = object + d[parts.last] ||= object end # copies directories and files from the real filesystem diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 464e9a7..83b6b78 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -36,6 +36,13 @@ class FakeFSTest < Test::Unit::TestCase assert File.directory?(path) end + def test_doesnt_overwrite_existing_directories + FileUtils.mkdir_p(path = "/path/to/dir") + assert File.exists?(path) + FileUtils.mkdir_p("/path/to") + assert File.exists?(path) + end + def test_can_create_symlinks FileUtils.mkdir_p(target = "/path/to/target") FileUtils.ln_s(target, "/path/to/link")