From 4e9355dc9ed4c9726caddbbb9c65129247a2b07c Mon Sep 17 00:00:00 2001 From: Greg Campbell Date: Tue, 6 Jul 2010 11:12:30 -0700 Subject: [PATCH] FileUtils.mv can now handle an array of sources Closes #40. Closes #56 --- lib/fakefs/fileutils.rb | 14 ++++++++------ test/fakefs_test.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/fakefs/fileutils.rb b/lib/fakefs/fileutils.rb index 18b0613..4315feb 100644 --- a/lib/fakefs/fileutils.rb +++ b/lib/fakefs/fileutils.rb @@ -95,12 +95,14 @@ module FakeFS end def mv(src, dest, options={}) - if target = FileSystem.find(src) - d_path = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest - FileSystem.add(d_path, target.entry.clone) - FileSystem.delete(src) - else - raise Errno::ENOENT, src + Array(src).each do |path| + if target = FileSystem.find(path) + dest_path = File.directory?(dest) ? File.join(dest, File.basename(path)) : dest + FileSystem.add(dest_path, target.entry.clone) + FileSystem.delete(path) + else + raise Errno::ENOENT, src + end end end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 3607c08..0948ce7 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -805,6 +805,15 @@ class FakeFSTest < Test::Unit::TestCase assert File.directory?('destdir') end + def test_mv_array + File.open('foo', 'w') {|f| f.write 'bar' } + File.open('baz', 'w') {|f| f.write 'binky' } + FileUtils.mkdir_p 'destdir' + FileUtils.mv %w(foo baz), 'destdir' + assert_equal('bar', File.open('destdir/foo') {|f| f.read }) + assert_equal('binky', File.open('destdir/baz') {|f| f.read }) + end + def test_cp_actually_works File.open('foo', 'w') {|f| f.write 'bar' } FileUtils.cp('foo', 'baz')