Stop mutating dependency specifications

This commit is contained in:
Jack Nagel 2013-09-13 09:51:23 -05:00
parent 448ce26980
commit f2ebc0e325
2 changed files with 12 additions and 1 deletions

View File

@ -40,7 +40,7 @@ class DependencyCollector
def build(spec)
spec, tags = case spec
when Hash then spec.shift
when Hash then destructure_spec_hash(spec)
else spec
end
@ -49,6 +49,10 @@ class DependencyCollector
private
def destructure_spec_hash(spec)
spec.each { |o| return o }
end
def parse_spec(spec, tags)
case spec
when String

View File

@ -128,4 +128,11 @@ class DependencyCollectorTests < Test::Unit::TestCase
def test_raises_typeerror_for_unknown_types
assert_raises(TypeError) { @d.add(Object.new) }
end
def test_does_not_mutate_dependency_spec
spec = { 'foo' => :optional }
copy = spec.dup
@d.add(spec)
assert_equal copy, spec
end
end