Check existence rather than rescue exceptions

This commit is contained in:
Jack Nagel 2013-04-09 19:40:08 -05:00
parent 67844c9012
commit bd4aaac96b
2 changed files with 17 additions and 1 deletions

View File

@ -80,7 +80,7 @@ class Formula
# if the dir is there, but it's empty we consider it not installed
def installed?
installed_prefix.children.length > 0 rescue false
(dir = installed_prefix).directory? && dir.children.length > 0
end
def pinable?

View File

@ -14,6 +14,22 @@ class FormulaTests < Test::Unit::TestCase
assert_kind_of Pathname, f.prefix
end
def test_installed?
f = TestBall.new
f.stubs(:installed_prefix).returns(stub(:directory? => false))
assert !f.installed?
f.stubs(:installed_prefix).returns(
stub(:directory? => true, :children => [])
)
assert !f.installed?
f.stubs(:installed_prefix).returns(
stub(:directory? => true, :children => [stub])
)
assert f.installed?
end
def test_class_naming
assert_equal 'ShellFm', Formula.class_s('shell.fm')
assert_equal 'Fooxx', Formula.class_s('foo++')