aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJack Nagel2012-04-06 17:28:44 -0500
committerJack Nagel2012-04-06 17:32:43 -0500
commit9614301be4f2647de6a0395b125c3a2ca69e3889 (patch)
treecbfd8e7083fe1a20f9d966bda61da83d922e4469 /Library/Homebrew
parent04bf4e5f8977e4e7792f39da87cdf2e67f8ca03c (diff)
downloadbrew-9614301be4f2647de6a0395b125c3a2ca69e3889.tar.bz2
Fix protection against overriding Formula#brew
The test for this previously passed, but only because the constructor for SoftwareSpecification was raising an exception. method_added needs to be a class method because methods are being defined on the class, not the object, and to test it properly we have to eval the class in the test itself. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/formula.rb4
-rw-r--r--Library/Homebrew/test/test_formula.rb21
2 files changed, 13 insertions, 12 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 82788869e..cecb904ab 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -551,8 +551,8 @@ private
instance_variable_set("@#{type}", class_value) if class_value
end
- def method_added method
- raise 'You cannot override Formula.brew' if method == 'brew'
+ def self.method_added method
+ raise 'You cannot override Formula.brew' if method == :brew
end
class << self
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 27761e289..ef3e0952b 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -19,15 +19,6 @@ class MostlyAbstractFormula <Formula
@homepage = 'http://example.com/'
end
-class TestBallOverrideBrew <Formula
- def initialize
- super "foo"
- end
- def brew
- end
-end
-
-
class FormulaTests < Test::Unit::TestCase
def test_prefix
@@ -48,7 +39,17 @@ class FormulaTests < Test::Unit::TestCase
end
def test_cant_override_brew
- assert_raises(RuntimeError) { TestBallOverrideBrew.new }
+ assert_raises(RuntimeError) do
+ eval <<-EOS
+ class TestBallOverrideBrew <Formula
+ def initialize
+ super "foo"
+ end
+ def brew
+ end
+ end
+ EOS
+ end
end
def test_abstract_formula