From 4f6259d180295e17baa64d6163665cbaee68f434 Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Sun, 31 May 2009 02:24:33 -0700 Subject: [PATCH] FileSystem.clone now works when cloning regular files. --- lib/fakefs.rb | 4 ++-- test/fakefs_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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