From a201579ef41097e59d72819ee84a63f7934aadd3 Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Sat, 13 Jun 2009 23:56:14 -0700 Subject: [PATCH] FileUtils.touch with multiple files was broken on 1.9. String#each does not exist in ruby 1.9, so Array() must be used. --- lib/fakefs.rb | 2 +- test/fakefs_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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)