diff options
| author | Jack Nagel | 2013-04-09 19:40:08 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-04-09 19:40:08 -0500 |
| commit | bd4aaac96b1f08d59a8e208095ac56ff446608df (patch) | |
| tree | f0d82f99b808e1369505d699a9a9d3929f3863a9 /Library | |
| parent | 67844c9012a8692d7435862b67a9c791a56abe01 (diff) | |
| download | brew-bd4aaac96b1f08d59a8e208095ac56ff446608df.tar.bz2 | |
Check existence rather than rescue exceptions
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_formula.rb | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index c994202e3..a6305eaaf 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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? diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index 918ff714f..bdeb398d8 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -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++') |
