Add FileTest#exist? Swap out FileTest for FakeFS::FileTest. Closes #14

This commit is contained in:
Scott Taylor 2009-11-24 04:27:26 -05:00
parent bdb3fa4ac0
commit 50193f2a75
4 changed files with 28 additions and 0 deletions

View File

@ -1,4 +1,5 @@
RealFile = File
RealFileTest = FileTest
RealFileUtils = FileUtils
RealDir = Dir
RealFileUtils::Dir = RealDir
@ -9,10 +10,12 @@ module FakeFS
Object.class_eval do
remove_const(:Dir)
remove_const(:File)
remove_const(:FileTest)
remove_const(:FileUtils)
const_set(:Dir, FakeFS::Dir)
const_set(:File, FakeFS::File)
const_set(:FileUtils, FakeFS::FileUtils)
const_set(:FileTest, FakeFS::FileTest)
end
end
@ -20,9 +23,11 @@ module FakeFS
Object.class_eval do
remove_const(:Dir)
remove_const(:File)
remove_const(:FileTest)
remove_const(:FileUtils)
const_set(:Dir, RealDir)
const_set(:File, RealFile)
const_set(:FileTest, RealFileTest)
const_set(:FileUtils, RealFileUtils)
end
end

7
lib/fakefs/file_test.rb Normal file
View File

@ -0,0 +1,7 @@
module FakeFS
class FileTest
def self.exist?(file_name)
File.exist?(file_name)
end
end
end

View File

@ -7,5 +7,6 @@ require 'fakefs/fake/symlink'
require 'fakefs/file_system'
require 'fakefs/fileutils'
require 'fakefs/file'
require 'fakefs/file_test'
require 'fakefs/dir'

View File

@ -1336,6 +1336,21 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal IO::SEEK_SET, File::SEEK_SET
end
def test_filetest_exists_return_correct_values
FileUtils.mkdir_p("/path/to/dir")
assert FileTest.exist?("/path/to/")
FileUtils.rmdir("/path/to/dir")
assert !FileTest.exist?("/path/to/dir")
end
def pathname_exists_returns_correct_value
FileUtils.touch "foo"
assert Pathname.new("foo").exist?
assert !Pathname.new("bar").exist?
end
def here(fname)
RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname)
end