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>
This commit is contained in:
Jack Nagel 2012-04-06 17:28:44 -05:00
parent 04bf4e5f89
commit 9614301be4
2 changed files with 13 additions and 12 deletions

View File

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

View File

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