Skip to content

Commit

Permalink
Allows FileUtils.mv to move into a directory.
Browse files Browse the repository at this point in the history
This addresses the first comment on fakefs#40.
  • Loading branch information
gcampbell authored and smtlaissezfaire committed Dec 27, 2010
1 parent 9505210 commit b91fddf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fakefs/fileutils.rb
Expand Up @@ -96,7 +96,8 @@ def cp_r(src, dest)

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
Expand Down
8 changes: 8 additions & 0 deletions test/fakefs_test.rb
Expand Up @@ -797,6 +797,14 @@ def test_mv_works_with_options
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')
Expand Down

0 comments on commit b91fddf

Please sign in to comment.