handle case where FileSystem.find has to find the root

This commit is contained in:
Matt Freels 2009-07-28 01:12:52 -07:00
parent 76002ea431
commit 9d09436dba
2 changed files with 15 additions and 3 deletions

View File

@ -21,6 +21,7 @@ module FakeFS
def find(path)
parts = path_parts(normalize_path(path))
return fs if parts.empty? # '/'
entries = find_recurser(fs, parts).flatten
@ -35,7 +36,7 @@ module FakeFS
return [] unless dir.respond_to? :[]
pattern , *parts = parts
matches = dir.reject {|k,v| /\A#{pattern.gsub('*', '.*')}\Z/ !~ k }.values
matches = dir.reject {|k,v| /\A#{pattern.gsub('?','.').gsub('*', '.*')}\Z/ !~ k }.values
if parts.empty? # we're done recursing
matches

View File

@ -205,9 +205,20 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/path/bar/baz'], Dir['/path/bar/*']
assert_equal ['/path/foo'], Dir['/path/foo']
# Unsupported so far. More hackery than I want to work on right now
assert_equal ['/path/foo', '/path/foobar'], Dir['/path/foo*']
assert_equal ['/path'], Dir['/path*']
assert_equal ['/path/foo', '/path/foobar'], Dir['/p*h/foo*']
assert_equal ['/path/foo', '/path/foobar'], Dir['/p??h/foo*']
FileUtils.cp_r '/path', '/otherpath'
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']
end
def test_dir_glob_handles_root
FileUtils.mkdir_p '/path'
# this fails. the root dir should be named '/' but it is '.'
#assert_equal ['/'], Dir['/']
end
def test_chdir_changes_directories_like_a_boss