diff --git a/lib/fakefs.rb b/lib/fakefs.rb index 3b04080..2534f36 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -97,7 +97,7 @@ module FakeFS end def touch(list, options={}) - list.each do |f| + Array(list).each do |f| directory = File.dirname(f) # FIXME this explicit check for '.' shouldn't need to happen if File.exists?(directory) || directory == '.' diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index ca3b3c7..dc20127 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -449,12 +449,21 @@ class FakeFSTest < Test::Unit::TestCase def test_files_can_be_touched FileUtils.touch('touched_file') assert File.exists?('touched_file') + list = ['newfile', 'another'] + FileUtils.touch(list) + list.each { |fp| assert(File.exists?(fp)) } 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') } + FileUtils.mkdir_p('subdir') + list = ['subdir/foo', 'nosubdir/bar'] + + assert_raises(Errno::ENOENT) { + FileUtils.touch(list) + } end def here(fname)