FileUtils.mv can now handle an array of sources

Closes #40.  Closes #56
This commit is contained in:
Greg Campbell 2010-07-06 11:12:30 -07:00 committed by Scott Taylor
parent b91fddf98b
commit 4e9355dc9e
2 changed files with 17 additions and 6 deletions

View File

@ -95,12 +95,14 @@ module FakeFS
end end
def mv(src, dest, options={}) def mv(src, dest, options={})
if target = FileSystem.find(src) Array(src).each do |path|
d_path = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest if target = FileSystem.find(path)
FileSystem.add(d_path, target.entry.clone) dest_path = File.directory?(dest) ? File.join(dest, File.basename(path)) : dest
FileSystem.delete(src) FileSystem.add(dest_path, target.entry.clone)
else FileSystem.delete(path)
raise Errno::ENOENT, src else
raise Errno::ENOENT, src
end
end end
end end

View File

@ -805,6 +805,15 @@ class FakeFSTest < Test::Unit::TestCase
assert File.directory?('destdir') assert File.directory?('destdir')
end 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 def test_cp_actually_works
File.open('foo', 'w') {|f| f.write 'bar' } File.open('foo', 'w') {|f| f.write 'bar' }
FileUtils.cp('foo', 'baz') FileUtils.cp('foo', 'baz')