Permalink
Browse files

Dir glob will accept multiple arguments.

  • Loading branch information...
marano committed Nov 19, 2010
1 parent 76b6bb1 commit f2d541cf3681e57e3413a08147cf40fca0677a69
Showing with 12 additions and 3 deletions.
  1. +9 −3 lib/fakefs/dir.rb
  2. +3 −0 test/fakefs_test.rb
View
@@ -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)
@@ -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)
View
@@ -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*']

0 comments on commit f2d541c

Please sign in to comment.