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

View File

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