 2e26afe556
			
		
	
	
		2e26afe556
		
	
	
	
	
		
			
			The initializer for Formula does a number of validations, but it does them in a weird order, and some attributes aren't validated under certain circumstances. This became even more of a mess when most software package attributes were moved into the SoftwareSpec class. This commit removes the last vestiges of storing these attributes as instance variables. In particular, it eliminates #set_instance_variable and #validate_variable, replacing them with methods that operate on SoftwareSpec instances, and generate more useful errors. Doing these validations unconditionally in the initializer means we bail out much earlier if the formula has invalid attributes or is not fully specified, and no longer need to validate in #prefix. Technically we don't need to validate in #brew either, but we continue to do so anyway as a safety measure, and because we cannot enforce calls to super in subclasses.
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require 'testing_env'
 | |
| require 'formula'
 | |
| 
 | |
| class FormulaValidationTests < Test::Unit::TestCase
 | |
|   def formula(*args, &block)
 | |
|     Class.new(Formula, &block).new(*args)
 | |
|   end
 | |
| 
 | |
|   def assert_invalid(attr, &block)
 | |
|     e = assert_raises(FormulaValidationError, &block)
 | |
|     assert_equal attr, e.attr
 | |
|   end
 | |
| 
 | |
|   def test_cant_override_brew
 | |
|     assert_raises(RuntimeError) do
 | |
|       Class.new(Formula) { def brew; end }
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_validates_name
 | |
|     assert_invalid :name do
 | |
|       formula "name with spaces" do
 | |
|         url "foo"
 | |
|         version "1.0"
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_validates_url
 | |
|     assert_invalid :url do
 | |
|       formula do
 | |
|         url ""
 | |
|         version "1"
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_validates_version
 | |
|     assert_invalid :version do
 | |
|       formula do
 | |
|         url "foo"
 | |
|         version "version with spaces"
 | |
|       end
 | |
|     end
 | |
| 
 | |
|     assert_invalid :version do
 | |
|       formula do
 | |
|         url "foo"
 | |
|         version ""
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_validates_when_initialize_overridden
 | |
|     assert_invalid :name do
 | |
|       formula do
 | |
|         def initialize; end
 | |
|       end.brew {}
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_head_only_valid
 | |
|     assert_nothing_raised do
 | |
|       formula do
 | |
|         head "foo"
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 |