Refactored touch to verify that the parent directories exist
This commit is contained in:
parent
27e24b2260
commit
bd97171227
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user