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' module FakeFS
class FakeFS
module FileUtils module FileUtils
extend self extend self
@ -43,17 +41,13 @@ class FakeFS
end end
def self.expand_path(path) def self.expand_path(path)
RealFile.expand_path(path) ::File.expand_path(path)
end end
def self.readlink(path) def self.readlink(path)
symlink = FileSystem.find(path) symlink = FileSystem.find(path)
FileSystem.find(symlink.target).to_s FileSystem.find(symlink.target).to_s
end end
def self.dirname(path)
RealFile.dirname(path)
end
end end
class Dir class Dir
@ -66,52 +60,8 @@ class FakeFS
end end
end end
module FileSystem
class MockDir < Hash extend self
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
def fs def fs
@fs ||= MockDir.new('.') @fs ||= MockDir.new('.')
@ -157,17 +107,50 @@ class FakeFS
def path_parts(path) def path_parts(path)
path.split(File::PATH_SEPARATOR) path.split(File::PATH_SEPARATOR)
end end
def method_missing(*args, &block)
fs.send(*args, &block)
end end
FileSystem = FakeFS.new('.') class MockDir < Hash
end attr_accessor :name, :parent
RealFile = File def initialize(name = nil, parent = nil)
RealFileUtils = FileUtils @name = name
RealDir = Dir @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 Object.class_eval do
remove_const(:Dir) 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