Write version_constraints as an array for inspec.lock (#2619)

* Modify version constraints to be an Array

This will allow both old and new versions of InSpec to parse the
`inspec.lock` correctly.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
Jerry Aldrich 2018-03-12 03:02:37 -10:00 committed by Jared Quick
parent c3064f0b0d
commit 439fcb5993
2 changed files with 20 additions and 2 deletions

View file

@ -80,7 +80,7 @@ module Inspec
h = {
'name' => name,
'resolved_source' => resolved_source,
'version_constraints' => version_constraints.to_s,
'version_constraints' => version_constraints,
}
if !dependencies.empty?

View file

@ -2,8 +2,9 @@ require 'helper'
require 'inspec/dependencies/requirement'
describe Inspec::Requirement do
let(:req) { Inspec::Requirement.new('foo', constraints, nil, nil, {}) }
describe '#source_satisfies_spec?' do
let(:req) { Inspec::Requirement.new('foo', constraints, nil, nil, {}) }
describe 'when there are no version constraints' do
let(:constraints) { nil }
@ -72,4 +73,21 @@ describe Inspec::Requirement do
end
end
end
describe '#to_hash' do
let(:constraints) { nil }
it 'returns the correct Hash' do
resolved_source = { compliance: 'spam', url: 'eggs', sha256: 'bacon' }
req.stubs(:resolved_source).returns(resolved_source)
req.stubs(:dependencies).returns({})
correct_hash = {
'name' => 'foo',
'resolved_source' => resolved_source,
'version_constraints' => [],
}
req.to_hash.must_equal correct_hash
end
end
end