diff --git a/lib/fakefs.rb b/lib/fakefs.rb index 2b73439..5085983 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -215,8 +215,8 @@ module FakeFS files.each do |f| if RealFile.file?(f) FileUtils.mkdir_p(File.dirname(f)) - File.open(f, 'w') do |f| - f.puts RealFile.read(f) + File.open(f, 'w') do |g| + g.print RealFile.open(f){|h| h.read } end elsif RealFile.directory?(f) FileUtils.mkdir_p(f) diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 1bc2ed2..5c26b39 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -286,4 +286,13 @@ class FakeFSTest < Test::Unit::TestCase FileUtils.cp_r 'blafgag', 'foo' end end + + def test_clone_clones_normal_files + def here(fname); File.expand_path(File.dirname(__FILE__)+'/'+fname); end + RealFile.open(here('foo'), 'w'){|f| f.write 'bar' } + FileSystem.clone(here('foo')) + assert_equal 'bar', File.open('foo'){|f| f.read } + ensure + RealFile.unlink(here('foo')) if RealFile.exists?(here('foo')) + end end