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