diff --git a/lib/fakefs.rb b/lib/fakefs.rb index 306ed40..7b8eccf 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -24,7 +24,7 @@ module FakeFS def cp_r(src, dest) if dir = FileSystem.find(src) - FileSystem.add(dest, dir.entry) + FileSystem.add(dest, dir.entry.clone) end end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 48e84df..ca96d82 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -271,4 +271,11 @@ class FakeFSTest < Test::Unit::TestCase FileUtils.mv 'foo', 'baz' assert_equal 'bar', File.open('baz'){|f| f.read } end + + def test_cp_r_doesnt_tangle_files_together + File.open('foo', 'w') {|f| f.write 'bar' } + FileUtils.cp_r('foo', 'baz') + File.open('baz', 'w') {|f| f.write 'quux' } + assert_equal 'bar', File.open('foo'){|f| f.read } + end end