Raise AlreadyLinkedError when a keg is already linked

This commit is contained in:
Jack Nagel 2014-04-21 09:40:24 -05:00
parent b2e8c4e79a
commit 6b5e92ac47
2 changed files with 11 additions and 2 deletions

View File

@ -4,6 +4,15 @@ require "formula_lock"
require "ostruct"
class Keg < Pathname
class AlreadyLinkedError < RuntimeError
def initialize(keg)
super <<-EOS.undent
Cannot link #{keg.fname}
Another version is already linked: #{keg.linked_keg_record.resolved_path}
EOS
end
end
class LinkError < RuntimeError
attr_reader :keg, :src, :dst
@ -169,7 +178,7 @@ class Keg < Pathname
end
def link mode=OpenStruct.new
raise "Cannot link #{fname}\nAnother version is already linked: #{linked_keg_record.resolved_path}" if linked_keg_record.directory?
raise AlreadyLinkedError.new(self) if linked_keg_record.directory?
ObserverPathnameExtension.reset_counts!

View File

@ -49,7 +49,7 @@ class LinkTests < Test::Unit::TestCase
def test_linking_fails_when_already_linked
@keg.link
assert_raise RuntimeError do
assert_raise Keg::AlreadyLinkedError do
shutup { @keg.link }
end
end