Merge pull request #101 from marano/issue_100
Dir glob will accept multiple arguments.
This commit is contained in:
commit
b363a8d470
@ -57,8 +57,8 @@ module FakeFS
|
||||
@contents[integer]
|
||||
end
|
||||
|
||||
def self.[](pattern)
|
||||
glob(pattern)
|
||||
def self.[](*pattern)
|
||||
glob pattern
|
||||
end
|
||||
|
||||
def self.exists?(path)
|
||||
@ -91,8 +91,14 @@ module FakeFS
|
||||
end
|
||||
|
||||
def self.glob(pattern, &block)
|
||||
files = [FileSystem.find(pattern) || []].flatten.map(&:to_s).sort
|
||||
block_given? ? files.each { |file| block.call(file) } : files
|
||||
matches_for_pattern = lambda { |matcher| [FileSystem.find(matcher) || []].flatten.map{|e| e.to_s}.sort }
|
||||
|
||||
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
|
||||
|
||||
def self.mkdir(string, integer = 0)
|
||||
|
@ -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/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'
|
||||
|
||||
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']
|
||||
|
Loading…
Reference in New Issue
Block a user