diff --git a/lib/fakefs/fileutils.rb b/lib/fakefs/fileutils.rb index 7229537..18b0613 100644 --- a/lib/fakefs/fileutils.rb +++ b/lib/fakefs/fileutils.rb @@ -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 diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index b17c433..3607c08 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -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')