diff --git a/lib/fakefs/fake/symlink.rb b/lib/fakefs/fake/symlink.rb index 750d095..132eead 100644 --- a/lib/fakefs/fake/symlink.rb +++ b/lib/fakefs/fake/symlink.rb @@ -1,7 +1,6 @@ module FakeFS class FakeSymlink attr_accessor :name, :target, :parent - alias_method :to_s, :name def initialize(target) @target = target @@ -19,6 +18,10 @@ module FakeFS parent.delete(self) end + def to_s + File.join(parent.to_s, name) + end + def respond_to?(method) entry.respond_to?(method) end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 9d999f8..9384e59 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -147,6 +147,13 @@ class FakeFSTest < Test::Unit::TestCase assert_equal target, File.readlink(link) end + def test_symlinks_to_symlinks + FileUtils.mkdir_p(target = "/path/to/foo/target") + FileUtils.ln_s(target, link1 = "/path/to/bar/symlink") + FileUtils.ln_s(link1, link2 = "/path/to/bar2/symlink") + assert_equal link1, File.readlink(link2) + end + def test_knows_symlinks_are_symlinks FileUtils.mkdir_p(target = "/path/to/target") FileUtils.ln_s(target, link = "/path/to/symlink")