Merge pull request #101 from marano/issue_100

Dir glob will accept multiple arguments.
This commit is contained in:
Eero Saynatkari 2011-10-25 09:51:47 -07:00
commit b363a8d470
2 changed files with 13 additions and 4 deletions

View File

@ -57,8 +57,8 @@ module FakeFS
@contents[integer] @contents[integer]
end end
def self.[](pattern) def self.[](*pattern)
glob(pattern) glob pattern
end end
def self.exists?(path) def self.exists?(path)
@ -91,8 +91,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

@ -742,6 +742,9 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*'] assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*']
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*']