Permalink
Browse files

FakeFS::Dir.glob works with a given block. Closes #39. Closes #55.

  • Loading branch information...
wijet authored and smtlaissezfaire committed Dec 26, 2010
1 parent 4e9355d commit 66c27ff31b9b958bf78eda62cd017ded1fc43495
Showing with 13 additions and 2 deletions.
  1. +3 −2 lib/fakefs/dir.rb
  2. +10 −0 test/fakefs_test.rb
View
@@ -78,8 +78,9 @@ def self.foreach(dirname, &block)
Dir.open(dirname) { |file| yield file }
end
def self.glob(pattern)
[FileSystem.find(pattern) || []].flatten.map{|e| e.to_s}.sort
def self.glob(pattern, &block)
files = [FileSystem.find(pattern) || []].flatten.map(&:to_s).sort
block_given? ? files.each { |file| block.call(file) } : files
end
def self.mkdir(string, integer = 0)
View
@@ -588,6 +588,16 @@ def test_dir_recursive_glob_ending_in_wildcards_returns_both_files_and_dirs
assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**']
end
def test_dir_glob_with_block
FileUtils.touch('foo')
FileUtils.touch('bar')
yielded = []
Dir.glob('*') { |file| yielded << file }
assert_equal 2, yielded.size
end
def test_should_report_pos_as_0_when_opening
File.open("/foo", "w") do |f|
f << "foobar"

0 comments on commit 66c27ff

Please sign in to comment.