brew/Library/Homebrew/test/test_dependencies.rb
Jack Nagel 429caf69a9 Remove Array subclassing
Inheriting from Array (and other core types) is problematic:

  - It exposes a very wide interface with many methods that are not
    really relevant to the subclass.
  - It can cause some weird side effects, as many Array operations are
    in C and have hardcoded return values; for example, combining two
    array subclasses returns a new Array instead of the subclass.

Avoid these problems using delegation and the Enumerable module where
applicable.
2013-01-07 14:32:14 -06:00

37 lines
929 B
Ruby

require 'testing_env'
require 'test/testball'
require 'dependencies'
class DependencyCollector
def find_dependency(name)
deps.find { |dep| dep.name == name }
end
end
class DependencyTests < Test::Unit::TestCase
def setup
@d = DependencyCollector.new
end
def test_dependency_creation
@d.add 'foo' => :build
@d.add 'bar' => ['--universal', :optional]
assert_not_nil @d.find_dependency('foo')
assert_equal 2, @d.find_dependency('bar').tags.length
end
def test_dependency_tags
assert Dependency.new('foo', :build).build?
assert Dependency.new('foo', [:build, :optional]).optional?
assert Dependency.new('foo', [:universal]).options.include? '--universal'
assert_empty Dependency.new('foo').tags
end
def test_no_duplicate_dependencies
@d.add 'foo'
@d.add 'foo' => :build
assert_equal 1, @d.deps.count
assert_empty @d.find_dependency('foo').tags
end
end