From 25c3b4e632aa9b7e6c46a56a1d3acd0ac5f892ad Mon Sep 17 00:00:00 2001 From: marano Date: Wed, 3 Nov 2010 14:09:23 -0200 Subject: [PATCH] Fixed issue where Dir glob would not work properly when doing /**/*. --- lib/fakefs/file_system.rb | 7 +++++-- test/fakefs_test.rb | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/fakefs/file_system.rb b/lib/fakefs/file_system.rb index 9eb02e9..2ab9b1f 100644 --- a/lib/fakefs/file_system.rb +++ b/lib/fakefs/file_system.rb @@ -109,11 +109,14 @@ module FakeFS 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 } + d.values.select{|f| f.is_a?(FakeFile) || f.is_a?(FakeDir) } end.flatten.uniq + when [] + parts = [] # end recursion + dir.values.flatten.uniq else directories_under(dir) end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 341da1b..d31bfd4 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -458,6 +458,13 @@ class FakeFSTest < Test::Unit::TestCase assert_equal ['/path/foo', '/path/foobar'], Dir['/p*h/foo*'] assert_equal ['/path/foo', '/path/foobar'], Dir['/p??h/foo*'] + assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*'] + assert_equal ['/path', '/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/**/*'] + + 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/**/*'] + FileUtils.cp_r '/path', '/otherpath' assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*'] @@ -478,11 +485,11 @@ class FakeFSTest < Test::Unit::TestCase 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_both_files_and_dirs 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/**'] + assert_equal ['/one/five.rb', '/one/two', '/one/two/three', '/one/two/three/four.rb'], Dir['/one/**/*'] + assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**'] end def test_should_report_pos_as_0_when_opening