Refactoring ln_sf and testing it
This commit is contained in:
parent
eb1cde19f9
commit
20ef508317
@ -26,13 +26,13 @@ module FakeFS
|
|||||||
alias_method :rm_rf, :rm
|
alias_method :rm_rf, :rm
|
||||||
alias_method :rm_r, :rm
|
alias_method :rm_r, :rm
|
||||||
|
|
||||||
def ln_s(target, path)
|
def ln_s(target, path, options = {})
|
||||||
raise Errno::EEXIST, path if FileSystem.find(path)
|
options = { :force => false }.merge(options)
|
||||||
|
(FileSystem.find(path) and !options[:force]) ? raise(Errno::EEXIST, path) : FileSystem.delete(path)
|
||||||
FileSystem.add(path, FakeSymlink.new(target))
|
FileSystem.add(path, FakeSymlink.new(target))
|
||||||
end
|
end
|
||||||
def ln_sf(target, path)
|
def ln_sf(target, path)
|
||||||
FileSystem.delete(path)
|
ln_s(target, path, { :force => true })
|
||||||
FileSystem.add(path, FakeSymlink.new(target))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,6 +74,20 @@ class FakeFSTest < Test::Unit::TestCase
|
|||||||
FileUtils.ln_s(target, '/path/to/link')
|
FileUtils.ln_s(target, '/path/to/link')
|
||||||
end
|
end
|
||||||
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
|
def test_can_follow_symlinks
|
||||||
FileUtils.mkdir_p(target = "/path/to/target")
|
FileUtils.mkdir_p(target = "/path/to/target")
|
||||||
|
Loading…
Reference in New Issue
Block a user