Refactored touch to verify that the parent directories exist

This commit is contained in:
Mark 2009-06-13 22:29:00 -07:00
parent 27e24b2260
commit bd97171227
2 changed files with 21 additions and 4 deletions

View File

@ -96,8 +96,19 @@ module FakeFS
chown(user, group, list, options={})
end
def touch(path)
FileSystem.add(path, MockFile.new)
def touch(list, options={})
list.each do |f|
if f =~ /(.+\/)/
dir_path = f.scan(/(.+\/)/)
if FileSystem.find(dir_path.to_s)
FileSystem.add(f, MockFile.new)
else
raise Errno::ENOENT, f
end
else
FileSystem.add(f, MockFile.new)
end
end
end
end

View File

@ -447,8 +447,14 @@ class FakeFSTest < Test::Unit::TestCase
end
def test_files_can_be_touched
FileUtils.touch(here("file"))
assert File.exists?(here("file"))
FileUtils.touch('touched_file')
assert File.exists?('touched_file')
end
def test_touch_does_not_work_if_the_dir_path_cannot_be_found
assert_raises(Errno::ENOENT) {
FileUtils.touch('this/path/should/not/be/here')
}
end
def here(fname)