Dir glob will accept multiple arguments.

This commit is contained in:
marano 2010-11-19 17:13:53 -02:00
parent fa2cacf2c3
commit 900be5173f
2 changed files with 13 additions and 4 deletions

View File

@ -52,8 +52,8 @@ module FakeFS
@contents[integer] @contents[integer]
end end
def self.[](pattern) def self.[](*pattern)
glob(pattern) glob pattern
end end
def self.chdir(dir, &blk) def self.chdir(dir, &blk)
@ -79,8 +79,14 @@ module FakeFS
end end
def self.glob(pattern, &block) def self.glob(pattern, &block)
files = [FileSystem.find(pattern) || []].flatten.map(&:to_s).sort matches_for_pattern = lambda { |matcher| [FileSystem.find(matcher) || []].flatten.map{|e| e.to_s}.sort }
block_given? ? files.each { |file| block.call(file) } : files
if pattern.is_a? Array
files = pattern.collect { |matcher| matches_for_pattern.call matcher }.flatten
else
files = matches_for_pattern.call pattern
end
return block_given? ? files.each { |file| block.call(file) } : files
end end
def self.mkdir(string, integer = 0) def self.mkdir(string, integer = 0)

View File

@ -561,6 +561,9 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*'] assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*']
assert_equal ['/path/bar/baz', '/path/bar2/baz'], Dir['/path/bar/**/*', '/path/bar2/**/*']
assert_equal ['/path/bar/baz', '/path/bar2/baz', '/path/bar/baz'], Dir['/path/ba*/**/*', '/path/bar/**/*']
FileUtils.cp_r '/path', '/otherpath' FileUtils.cp_r '/path', '/otherpath'
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*'] assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']