Allows FileUtils.mv to move into a directory.

This addresses the first comment on #40.
This commit is contained in:
Greg Campbell 2010-07-06 11:04:36 -07:00 committed by Scott Taylor
parent 9505210a90
commit b91fddf98b
2 changed files with 10 additions and 1 deletions

View File

@ -96,7 +96,8 @@ module FakeFS
def mv(src, dest, options={})
if target = FileSystem.find(src)
FileSystem.add(dest, target.entry.clone)
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

View File

@ -797,6 +797,14 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal('bar', File.open('baz') { |f| f.read })
end
def test_mv_to_directory
File.open('foo', 'w') {|f| f.write 'bar'}
FileUtils.mkdir_p 'destdir'
FileUtils.mv 'foo', 'destdir'
assert_equal('bar', File.open('destdir/foo') {|f| f.read })
assert File.directory?('destdir')
end
def test_cp_actually_works
File.open('foo', 'w') {|f| f.write 'bar' }
FileUtils.cp('foo', 'baz')