Dir.entries returns only basenames, not full paths - make FakeFS match that behavior
This commit is contained in:
parent
7444ef50b3
commit
838274f965
@ -71,7 +71,7 @@ module FakeFS
|
|||||||
|
|
||||||
def self.entries(dirname)
|
def self.entries(dirname)
|
||||||
raise SystemCallError, dirname unless FileSystem.find(dirname)
|
raise SystemCallError, dirname unless FileSystem.find(dirname)
|
||||||
Dir.new(dirname).map { |file| file }
|
Dir.new(dirname).map { |file| File.basename(file) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.foreach(dirname, &block)
|
def self.foreach(dirname, &block)
|
||||||
|
@ -910,6 +910,20 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
test.each { |t| assert yielded.include?(t) }
|
test.each { |t| assert yielded.include?(t) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_directory_entries_works_with_trailing_slash
|
||||||
|
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
|
||||||
|
|
||||||
|
FileUtils.mkdir_p('/this/path/should/be/here')
|
||||||
|
|
||||||
|
test.each do |f|
|
||||||
|
FileUtils.touch("/this/path/should/be/here/#{f}")
|
||||||
|
end
|
||||||
|
|
||||||
|
yielded = Dir.entries('/this/path/should/be/here/')
|
||||||
|
assert yielded.size == test.size
|
||||||
|
test.each { |t| assert yielded.include?(t) }
|
||||||
|
end
|
||||||
|
|
||||||
def test_directory_foreach
|
def test_directory_foreach
|
||||||
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
|
test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user