FileSystem.clone now clones directories and dot files.
This commit is contained in:
parent
c0be5bd8f2
commit
364dc66ee5
@ -4,6 +4,8 @@ require 'pathname'
|
|||||||
RealFile = File
|
RealFile = File
|
||||||
RealFileUtils = FileUtils
|
RealFileUtils = FileUtils
|
||||||
RealDir = Dir
|
RealDir = Dir
|
||||||
|
RealFileUtils::Dir = RealDir
|
||||||
|
RealFileUtils::File = RealFile
|
||||||
|
|
||||||
module FakeFS
|
module FakeFS
|
||||||
module FileUtils
|
module FileUtils
|
||||||
@ -229,7 +231,8 @@ module FakeFS
|
|||||||
def clone(path)
|
def clone(path)
|
||||||
path = File.expand_path(path)
|
path = File.expand_path(path)
|
||||||
pattern = File.join(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|
|
files.each do |f|
|
||||||
if RealFile.file?(f)
|
if RealFile.file?(f)
|
||||||
|
@ -345,7 +345,6 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_clone_clones_normal_files
|
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' }
|
RealFile.open(here('foo'), 'w'){|f| f.write 'bar' }
|
||||||
assert !File.exists?(here('foo'))
|
assert !File.exists?(here('foo'))
|
||||||
FileSystem.clone(here('foo'))
|
FileSystem.clone(here('foo'))
|
||||||
@ -354,6 +353,26 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
RealFile.unlink(here('foo')) if RealFile.exists?(here('foo'))
|
RealFile.unlink(here('foo')) if RealFile.exists?(here('foo'))
|
||||||
end
|
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
|
def test_putting_a_dot_at_end_copies_the_contents
|
||||||
FileUtils.mkdir_p 'subdir'
|
FileUtils.mkdir_p 'subdir'
|
||||||
Dir.chdir('subdir'){ File.open('foo', 'w'){|f| f.write 'footext' } }
|
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 }
|
assert_equal 'works', File.open('new/nother'){|f| f.read }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def here(fname)
|
||||||
|
RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user