Eliminate nil check on path parameter

This commit is contained in:
Jack Nagel 2014-02-21 20:07:41 -05:00
parent d31bee2e5b
commit e3e14a0cdf
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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