Stop mutating dependency specifications
This commit is contained in:
parent
448ce26980
commit
f2ebc0e325
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user