Add FileTest#exist? Swap out FileTest for FakeFS::FileTest. Closes #14
This commit is contained in:
parent
bdb3fa4ac0
commit
50193f2a75
@ -1,4 +1,5 @@
|
|||||||
RealFile = File
|
RealFile = File
|
||||||
|
RealFileTest = FileTest
|
||||||
RealFileUtils = FileUtils
|
RealFileUtils = FileUtils
|
||||||
RealDir = Dir
|
RealDir = Dir
|
||||||
RealFileUtils::Dir = RealDir
|
RealFileUtils::Dir = RealDir
|
||||||
@ -9,10 +10,12 @@ module FakeFS
|
|||||||
Object.class_eval do
|
Object.class_eval do
|
||||||
remove_const(:Dir)
|
remove_const(:Dir)
|
||||||
remove_const(:File)
|
remove_const(:File)
|
||||||
|
remove_const(:FileTest)
|
||||||
remove_const(:FileUtils)
|
remove_const(:FileUtils)
|
||||||
const_set(:Dir, FakeFS::Dir)
|
const_set(:Dir, FakeFS::Dir)
|
||||||
const_set(:File, FakeFS::File)
|
const_set(:File, FakeFS::File)
|
||||||
const_set(:FileUtils, FakeFS::FileUtils)
|
const_set(:FileUtils, FakeFS::FileUtils)
|
||||||
|
const_set(:FileTest, FakeFS::FileTest)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -20,9 +23,11 @@ module FakeFS
|
|||||||
Object.class_eval do
|
Object.class_eval do
|
||||||
remove_const(:Dir)
|
remove_const(:Dir)
|
||||||
remove_const(:File)
|
remove_const(:File)
|
||||||
|
remove_const(:FileTest)
|
||||||
remove_const(:FileUtils)
|
remove_const(:FileUtils)
|
||||||
const_set(:Dir, RealDir)
|
const_set(:Dir, RealDir)
|
||||||
const_set(:File, RealFile)
|
const_set(:File, RealFile)
|
||||||
|
const_set(:FileTest, RealFileTest)
|
||||||
const_set(:FileUtils, RealFileUtils)
|
const_set(:FileUtils, RealFileUtils)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
7
lib/fakefs/file_test.rb
Normal file
7
lib/fakefs/file_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module FakeFS
|
||||||
|
class FileTest
|
||||||
|
def self.exist?(file_name)
|
||||||
|
File.exist?(file_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -7,5 +7,6 @@ require 'fakefs/fake/symlink'
|
|||||||
require 'fakefs/file_system'
|
require 'fakefs/file_system'
|
||||||
require 'fakefs/fileutils'
|
require 'fakefs/fileutils'
|
||||||
require 'fakefs/file'
|
require 'fakefs/file'
|
||||||
|
require 'fakefs/file_test'
|
||||||
require 'fakefs/dir'
|
require 'fakefs/dir'
|
||||||
|
|
||||||
|
@ -1336,6 +1336,21 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
assert_equal IO::SEEK_SET, File::SEEK_SET
|
assert_equal IO::SEEK_SET, File::SEEK_SET
|
||||||
end
|
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)
|
def here(fname)
|
||||||
RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname)
|
RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user