Skip to content

Commit

Permalink
Dir glob will accept multiple arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
marano committed Nov 19, 2010
1 parent 76b6bb1 commit f2d541c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/fakefs/dir.rb
Expand Up @@ -52,8 +52,8 @@ def seek(integer)
@contents[integer]
end

def self.[](pattern)
glob(pattern)
def self.[](*pattern)
glob pattern
end

def self.chdir(dir, &blk)
Expand All @@ -79,7 +79,13 @@ def self.foreach(dirname, &block)
end

def self.glob(pattern)
[FileSystem.find(pattern) || []].flatten.map{|e| e.to_s}.sort
matches_for_pattern = lambda { |matcher| [FileSystem.find(matcher) || []].flatten.map{|e| e.to_s}.sort }

if pattern.is_a? Array
return pattern.collect { |matcher| matches_for_pattern.call matcher }.flatten
else
return matches_for_pattern.call pattern
end
end

def self.mkdir(string, integer = 0)
Expand Down
3 changes: 3 additions & 0 deletions test/fakefs_test.rb
Expand Up @@ -465,6 +465,9 @@ def test_dir_globs_paths

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*']
Expand Down

0 comments on commit f2d541c

Please sign in to comment.