From 838274f965d5a9182f424c5bdbcbf58f2bc08be6 Mon Sep 17 00:00:00 2001 From: Scott Barron Date: Mon, 26 Oct 2009 22:51:26 +0800 Subject: [PATCH] Dir.entries returns only basenames, not full paths - make FakeFS match that behavior --- lib/fakefs/dir.rb | 2 +- test/fakefs_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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' ]