Skip to content

Commit

Permalink
Recursive globbing better mimics standard lib Dir
Browse files Browse the repository at this point in the history
Patterns ending in wildcards now return files and directories.
  • Loading branch information
logicaltext committed Jan 11, 2010
1 parent 3c0f3e9 commit 0ce32cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/fakefs/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ def find_recurser(dir, parts)
matches = case pattern
when '**'
case parts
when ['*'], []
when ['*']
parts = [] # end recursion
directories_under(dir).map do |d|
d.values.select{|f| f.is_a? FakeFile }
end.flatten.uniq
directories_under(dir).map { |d| d.values }.flatten.uniq
when []
parts = [] # end recursion
dir.values
else
directories_under(dir)
end
Expand Down
14 changes: 10 additions & 4 deletions test/fakefs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,18 @@ def test_dir_glob_handles_recursive_globs
assert_equal ['/one/two/three'], Dir['/one/**/three']
end

def test_dir_recursive_glob_ending_in_wildcards_only_returns_files
def test_dir_recursive_glob_ending_in_wildcards_returns_files_and_directories
File.open('/one/two/three/four.rb', 'w')
File.open('/one/five.rb', 'w')
assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**/*']
assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**']
end

expected = [ '/one/five.rb', '/one/two' ]
expected += [ '/one/two/three', '/one/two/three/four.rb' ]
assert_equal expected, Dir['/one/**/*']

expected = ['/one/five.rb', '/one/two']
assert_equal expected, Dir['/one/**']
end


def test_should_report_pos_as_0_when_opening
File.open("/foo", "w") do |f|
Expand Down

0 comments on commit 0ce32cb

Please sign in to comment.