Refactoring ln_sf and testing it

This commit is contained in:
dmathieu 2009-10-09 05:34:22 +08:00 committed by Chris Wanstrath
parent eb1cde19f9
commit 20ef508317
2 changed files with 18 additions and 4 deletions

View File

@ -26,13 +26,13 @@ module FakeFS
alias_method :rm_rf, :rm
alias_method :rm_r, :rm
def ln_s(target, path)
raise Errno::EEXIST, path if FileSystem.find(path)
def ln_s(target, path, options = {})
options = { :force => false }.merge(options)
(FileSystem.find(path) and !options[:force]) ? raise(Errno::EEXIST, path) : FileSystem.delete(path)
FileSystem.add(path, FakeSymlink.new(target))
end
def ln_sf(target, path)
FileSystem.delete(path)
FileSystem.add(path, FakeSymlink.new(target))
ln_s(target, path, { :force => true })
end

View File

@ -75,6 +75,20 @@ class FakeFSTest < Test::Unit::TestCase
end
end
def test_can_force_creation_of_symlinks
FileUtils.mkdir_p(target = "/path/to/first/target")
FileUtils.ln_s(target, "/path/to/link")
assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
FileUtils.ln_s(target, '/path/to/link', :force => true)
end
def test_create_symlink_using_ln_sf
FileUtils.mkdir_p(target = "/path/to/first/target")
FileUtils.ln_s(target, "/path/to/link")
assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
FileUtils.ln_sf(target, '/path/to/link')
end
def test_can_follow_symlinks
FileUtils.mkdir_p(target = "/path/to/target")
FileUtils.ln_s(target, link = "/path/to/symlink")