From a926ebf1c56ab36daa6f67115c7d641b8dbb517a Mon Sep 17 00:00:00 2001 From: Myles Eftos Date: Mon, 14 Sep 2009 01:41:00 +0800 Subject: [PATCH] Added File.extname and FileUtils.rmdir --- fakefs.gemspec | 2 +- lib/fakefs/file.rb | 4 ++++ lib/fakefs/fileutils.rb | 8 ++++++++ lib/fakefs/version.rb | 2 +- test/fakefs_test.rb | 11 +++++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fakefs.gemspec b/fakefs.gemspec index adb8f72..9579d91 100644 --- a/fakefs.gemspec +++ b/fakefs.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{fakefs} - s.version = "0.1.3" + s.version = "0.1.4" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Chris Wanstrath"] diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb index 37230e6..85b66bb 100644 --- a/lib/fakefs/file.rb +++ b/lib/fakefs/file.rb @@ -2,6 +2,10 @@ module FakeFS class File PATH_SEPARATOR = '/' + def self.extname(path) + RealFile.extname(path) + end + def self.join(*parts) parts * PATH_SEPARATOR end diff --git a/lib/fakefs/fileutils.rb b/lib/fakefs/fileutils.rb index d9c182c..8ae66de 100644 --- a/lib/fakefs/fileutils.rb +++ b/lib/fakefs/fileutils.rb @@ -6,6 +6,14 @@ module FakeFS FileSystem.add(path, FakeDir.new) end + def rmdir(list, options = {}) + list = [ list ] unless list.is_a?(Array) + list.each do |l| + raise Errno::ENOENT, l unless FileSystem.find(l) + rm(l) + end + end + def rm(path) FileSystem.delete(path) end diff --git a/lib/fakefs/version.rb b/lib/fakefs/version.rb index a77c5c8..f1448ed 100644 --- a/lib/fakefs/version.rb +++ b/lib/fakefs/version.rb @@ -1,6 +1,6 @@ module FakeFS module Version - VERSION = "0.1.3" + VERSION = "0.1.4" def self.to_s VERSION diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index ac184fb..e732f12 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -25,6 +25,13 @@ class FakeFSTest < Test::Unit::TestCase FileUtils.mkdir_p("/path/to/dir") assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir'] end + + def test_can_delete_directories + FileUtils.mkdir_p("/path/to/dir") + FileUtils.rmdir("/path/to/dir") + assert File.exists?("/path/to/") + assert File.exists?("/path/to/dir") == false + end def test_knows_directories_exist FileUtils.mkdir_p(path = "/path/to/dir") @@ -532,6 +539,10 @@ class FakeFSTest < Test::Unit::TestCase } end + def test_extname + assert File.extname("test.doc") == ".doc" + end + # Directory tests def test_new_directory FileUtils.mkdir_p('/this/path/should/be/here')