aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-02-21 20:07:41 -0500
committerJack Nagel2014-02-21 20:07:41 -0500
commitc44fb1b78c945c71854b669e6bcfbf5eb5a45724 (patch)
treecd3e400818577084b4da192fde715369e8e08a16
parent487f4f064ca724327e1eeedbb68832b0543979a4 (diff)
downloadhomebrew-c44fb1b78c945c71854b669e6bcfbf5eb5a45724.tar.bz2
Eliminate nil check on path parameter
-rw-r--r--Library/Homebrew/formula.rb5
-rw-r--r--Library/Homebrew/test/test_formula.rb14
2 files changed, 16 insertions, 3 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 38e8d8f1f..d70b59a9c 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -30,10 +30,9 @@ class Formula
attr_reader :cxxstdlib
# Homebrew determines the name
- def initialize name='__UNKNOWN__', path=nil
+ def initialize name='__UNKNOWN__', path=self.class.path(name)
@name = name
- # If we got an explicit path, use that, else determine from the name
- @path = path.nil? ? self.class.path(name) : path
+ @path = path
@homepage = self.class.homepage
set_spec :stable
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 51b6d8813..dd4f9a3e3 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -4,6 +4,20 @@ require 'test/testball'
class FormulaTests < Test::Unit::TestCase
include VersionAssertions
+ def test_formula_path_initialization
+ name = "formula_name"
+ klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
+
+ f = klass.new(name)
+ assert_equal Formula.path(name), f.path
+
+ f = klass.new(name, path = Object.new)
+ assert_equal path, f.path
+
+ f = klass.new(name, nil)
+ assert_nil f.path
+ end
+
def test_prefix
f = TestBall.new
assert_equal HOMEBREW_CELLAR/f.name/'0.1', f.prefix