lib/fakefs/fileutils.rb in fakefs-0.3.1 vs lib/fakefs/fileutils.rb in fakefs-0.3.2

- old
+ new

@@ -4,11 +4,20 @@ def mkdir_p(path, options = {}) FileSystem.add(path, FakeDir.new) end alias_method :mkpath, :mkdir_p + alias_method :makedirs, :mkdir_p + def mkdir(path) + parent = path.split('/') + parent.pop + raise Errno::ENOENT, "No such file or directory - #{path}" unless parent.join == "" || FileSystem.find(parent.join('/')) + raise Errno::EEXIST, "File exists - #{path}" if FileSystem.find(path) + FileSystem.add(path, FakeDir.new) + end + def rmdir(list, options = {}) list = [ list ] unless list.is_a?(Array) list.each do |l| parent = l.split('/') parent.pop @@ -85,14 +94,17 @@ FileSystem.add(dest, dir.entry.clone) end end def mv(src, dest, options={}) - if target = FileSystem.find(src) - FileSystem.add(dest, target.entry.clone) - FileSystem.delete(src) - else - raise Errno::ENOENT, src + Array(src).each do |path| + if target = FileSystem.find(path) + dest_path = File.directory?(dest) ? File.join(dest, File.basename(path)) : dest + FileSystem.add(dest_path, target.entry.clone) + FileSystem.delete(path) + else + raise Errno::ENOENT, path + end end end def chown(user, group, list, options={}) list = Array(list)