From 005ddaaeb2b2881391c31ac9846a55ce5a42c206 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 18 Feb 2011 16:14:13 -0500 Subject: [PATCH] allow for {p,q} literals in globs --- lib/fakefs/file_system.rb | 5 ++++- test/fakefs_test.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fakefs/file_system.rb b/lib/fakefs/file_system.rb index 2ab9b1f..402b584 100644 --- a/lib/fakefs/file_system.rb +++ b/lib/fakefs/file_system.rb @@ -121,7 +121,10 @@ module FakeFS directories_under(dir) end else - dir.reject {|k,v| /\A#{pattern.gsub('?','.').gsub('*', '.*')}\Z/ !~ k }.values + pattern = pattern.gsub('?','.').gsub('*', '.*') + pattern = pattern.gsub(%r{\{([^\}]+)\}}) { |all| "(#{$1.gsub(',', '|')})" } + + dir.reject {|k,v| /\A#{pattern}\Z/ !~ k }.values end if parts.empty? # we're done recursing diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index aee0bf1..c6028df 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -569,6 +569,8 @@ class FakeFSTest < Test::Unit::TestCase assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*'] + assert_equal ['/path/bar', '/path/foo'], Dir['/path/{foo,bar}'].sort + FileUtils.cp_r '/path', '/otherpath' assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']