FileSystem.clone now clones directories and dot files.

This commit is contained in:
Jeff Hodges 2009-06-01 23:54:04 -07:00
parent c0be5bd8f2
commit 364dc66ee5
2 changed files with 28 additions and 2 deletions

View File

@ -4,6 +4,8 @@ require 'pathname'
RealFile = File
RealFileUtils = FileUtils
RealDir = Dir
RealFileUtils::Dir = RealDir
RealFileUtils::File = RealFile
module FakeFS
module FileUtils
@ -229,7 +231,8 @@ module FakeFS
def clone(path)
path = File.expand_path(path)
pattern = File.join(path, '**', '*')
files = RealFile.file?(path) ? [path] : RealDir.glob(pattern)
dot_pattern = File.join(path, '**', '.*')
files = RealFile.file?(path) ? [path] : [path] + RealDir.glob([pattern, dot_pattern])
files.each do |f|
if RealFile.file?(f)

View File

@ -345,7 +345,6 @@ class FakeFSTest < Test::Unit::TestCase
end
def test_clone_clones_normal_files
def here(fname); File.expand_path(File.dirname(__FILE__)+'/'+fname); end
RealFile.open(here('foo'), 'w'){|f| f.write 'bar' }
assert !File.exists?(here('foo'))
FileSystem.clone(here('foo'))
@ -354,6 +353,26 @@ class FakeFSTest < Test::Unit::TestCase
RealFile.unlink(here('foo')) if RealFile.exists?(here('foo'))
end
def test_clone_clones_directories
RealFileUtils.mkdir_p(here('subdir'))
FileSystem.clone(here('subdir'))
assert File.exists?(here('subdir')), 'subdir was cloned'
assert File.directory?(here('subdir')), 'subdir is a directory'
ensure
RealFileUtils.rm_rf(here('subdir')) if RealFile.exists?(here('subdir'))
end
def test_clone_clones_dot_files
RealFileUtils.mkdir_p(here('subdir/.bar'))
assert !File.exists?(here('subdir'))
FileSystem.clone(here('subdir'))
assert_equal ['.bar'], FileSystem.find(here('subdir')).keys
ensure
RealFileUtils.rm_rf(here('subdir')) if RealFile.exists?(here('subdir'))
end
def test_putting_a_dot_at_end_copies_the_contents
FileUtils.mkdir_p 'subdir'
Dir.chdir('subdir'){ File.open('foo', 'w'){|f| f.write 'footext' } }
@ -374,4 +393,8 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal 'works', File.open('new/nother'){|f| f.read }
end
def here(fname)
RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname)
end
end