From 1403c5b421bd43abafc189ededa428ce73a82274 Mon Sep 17 00:00:00 2001 From: Myles Eftos Date: Sun, 13 Sep 2009 22:50:34 +0800 Subject: [PATCH] Fixed Dir read method to strip the path, so it matches the Ruby Dir path. Bumped version number --- fakefs.gemspec | 2 +- lib/fakefs/dir.rb | 4 ++-- lib/fakefs/version.rb | 2 +- test/fakefs_test.rb | 56 ++++++++++++++++++++++++------------------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/fakefs.gemspec b/fakefs.gemspec index c078bd4..adb8f72 100644 --- a/fakefs.gemspec +++ b/fakefs.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{fakefs} - s.version = "0.1.2" + s.version = "0.1.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Chris Wanstrath"] diff --git a/lib/fakefs/dir.rb b/lib/fakefs/dir.rb index ca8c0f4..c56e395 100644 --- a/lib/fakefs/dir.rb +++ b/lib/fakefs/dir.rb @@ -39,7 +39,7 @@ module FakeFS raise IOError, "closed directory" if @pointer == nil n = @contents[@pointer] @pointer += 1 - n.to_s if n + n.to_s.gsub(path + '/', '') if n end def rewind @@ -97,7 +97,7 @@ module FakeFS end end - def tmpdir + def self.tmpdir '/tmp' end diff --git a/lib/fakefs/version.rb b/lib/fakefs/version.rb index 06f3b1d..a77c5c8 100644 --- a/lib/fakefs/version.rb +++ b/lib/fakefs/version.rb @@ -1,6 +1,6 @@ module FakeFS module Version - VERSION = "0.1.1" + VERSION = "0.1.3" def self.to_s VERSION diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index f47dc90..ac184fb 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -558,12 +558,12 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_each - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -583,10 +583,10 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_pos - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -605,10 +605,11 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_pos_assign - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -619,10 +620,11 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_read - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -638,10 +640,11 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_read_past_length - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -665,10 +668,11 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_rewind - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -681,10 +685,11 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_seek - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.new('/this/path/should/be/here') @@ -702,10 +707,11 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_class_delete_does_not_act_on_non_empty_directory - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end assert_raises(SystemCallError) do @@ -714,12 +720,12 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_entries - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end yielded = Dir.entries('/this/path/should/be/here') @@ -728,12 +734,12 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_foreach - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end yielded = [] @@ -764,12 +770,12 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_open - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end dir = Dir.open('/this/path/should/be/here') @@ -777,12 +783,12 @@ class FakeFSTest < Test::Unit::TestCase end def test_directory_open_block - test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] + 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(f) + FileUtils.touch("/this/path/should/be/here/#{f}") end yielded = [] @@ -795,7 +801,7 @@ class FakeFSTest < Test::Unit::TestCase end def test_tmpdir - assert Dir.tmp_dir == "/tmp" + assert Dir.tmpdir == "/tmp" end def here(fname)