Allows FileUtils.mv to move into a directory.
This addresses the first comment on #40.
This commit is contained in:
parent
9505210a90
commit
b91fddf98b
@ -96,7 +96,8 @@ module FakeFS
|
|||||||
|
|
||||||
def mv(src, dest, options={})
|
def mv(src, dest, options={})
|
||||||
if target = FileSystem.find(src)
|
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)
|
FileSystem.delete(src)
|
||||||
else
|
else
|
||||||
raise Errno::ENOENT, src
|
raise Errno::ENOENT, src
|
||||||
|
@ -797,6 +797,14 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
assert_equal('bar', File.open('baz') { |f| f.read })
|
assert_equal('bar', File.open('baz') { |f| f.read })
|
||||||
end
|
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
|
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')
|
||||||
|
Loading…
Reference in New Issue
Block a user