Revert "start adding basic tests for fakefs"

This reverts commit f451efdf2d.
This commit is contained in:
Chris Wanstrath 2009-05-29 09:48:28 -07:00
parent f451efdf2d
commit c1973ebcb3
2 changed files with 50 additions and 82 deletions

View File

@ -1,6 +1,4 @@
require 'fileutils'
class FakeFS
module FakeFS
module FileUtils
extend self
@ -43,17 +41,13 @@ class FakeFS
end
def self.expand_path(path)
RealFile.expand_path(path)
::File.expand_path(path)
end
def self.readlink(path)
symlink = FileSystem.find(path)
FileSystem.find(symlink.target).to_s
end
def self.dirname(path)
RealFile.dirname(path)
end
end
class Dir
@ -66,52 +60,8 @@ class FakeFS
end
end
class MockDir < Hash
attr_accessor :name, :parent
def initialize(name = nil, parent = nil)
@name = name
@parent = parent
end
def files
values
end
def entry
self
end
def to_s
if parent && parent.to_s != '.'
parent.to_s + '/' + name
else
name
end
end
end
class MockSymlink
attr_accessor :name, :target
alias_method :to_s, :name
def initialize(target)
@target = target
end
def inspect
"symlink(#{target.split('/').last})"
end
def entry
FileSystem.find(target)
end
def method_missing(*args, &block)
entry.send(*args, &block)
end
end
module FileSystem
extend self
def fs
@fs ||= MockDir.new('.')
@ -157,17 +107,50 @@ class FakeFS
def path_parts(path)
path.split(File::PATH_SEPARATOR)
end
def method_missing(*args, &block)
fs.send(*args, &block)
end
FileSystem = FakeFS.new('.')
end
class MockDir < Hash
attr_accessor :name, :parent
RealFile = File
RealFileUtils = FileUtils
RealDir = Dir
def initialize(name = nil, parent = nil)
@name = name
@parent = parent
end
def entry
self
end
def to_s
if parent && parent.to_s != '.'
parent.to_s + '/' + name
else
name
end
end
end
class MockSymlink
attr_accessor :name, :target
alias_method :to_s, :name
def initialize(target)
@target = target
end
def inspect
"symlink(#{target.split('/').last})"
end
def entry
FileSystem.find(target)
end
def method_missing(*args, &block)
entry.send(*args, &block)
end
end
end
Object.class_eval do
remove_const(:Dir)

View File

@ -1,15 +0,0 @@
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'fakefs'
require 'test/unit'
class FakeFSTest < Test::Unit::TestCase
def test_can_be_initialized_empty
fs = FakeFS.new('.')
assert_equal 0, fs.files.size
end
def test_can_be_initialized_with_an_existing_directory
fs = FakeFS.new(File.expand_path(File.dirname(__FILE__)))
assert_equal 1, fs.files.size
end
end