diff --git a/lib/fakefs/dir.rb b/lib/fakefs/dir.rb index c5ac3ea..e241661 100644 --- a/lib/fakefs/dir.rb +++ b/lib/fakefs/dir.rb @@ -71,7 +71,7 @@ module FakeFS def self.entries(dirname) raise SystemCallError, dirname unless FileSystem.find(dirname) - Dir.new(dirname).map { |file| file } + Dir.new(dirname).map { |file| File.basename(file) } end def self.foreach(dirname, &block) diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index f1f6712..a30c2b9 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -910,6 +910,20 @@ class FakeFSTest < Test::Unit::TestCase test.each { |t| assert yielded.include?(t) } 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 test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]