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

This commit is contained in:
Mariusz Pietrzyk 2010-12-26 01:05:26 +01:00 committed by Scott Taylor
parent 4e9355dc9e
commit 66c27ff31b
2 changed files with 13 additions and 2 deletions

View File

@ -78,8 +78,9 @@ module FakeFS
Dir.open(dirname) { |file| yield file } Dir.open(dirname) { |file| yield file }
end end
def self.glob(pattern) def self.glob(pattern, &block)
[FileSystem.find(pattern) || []].flatten.map{|e| e.to_s}.sort files = [FileSystem.find(pattern) || []].flatten.map(&:to_s).sort
block_given? ? files.each { |file| block.call(file) } : files
end end
def self.mkdir(string, integer = 0) def self.mkdir(string, integer = 0)

View File

@ -588,6 +588,16 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**'] assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**']
end 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 def test_should_report_pos_as_0_when_opening
File.open("/foo", "w") do |f| File.open("/foo", "w") do |f|
f << "foobar" f << "foobar"