Merge pull request #247 from chef/fix-describe-id

bugfix: support multiple computed calls to describe
This commit is contained in:
Christoph Hartmann 2015-11-19 14:30:09 +01:00
commit f32d850618
2 changed files with 16 additions and 4 deletions

View file

@ -5,6 +5,7 @@
require 'inspec/rule'
require 'inspec/dsl'
require 'rspec/core/dsl'
require 'securerandom'
module Inspec
class ProfileContext # rubocop:disable Metrics/ClassLength
@ -110,7 +111,7 @@ module Inspec
define_method :describe do |*args, &block|
path = block.source_location[0]
line = block.source_location[1]
id = "#{File.basename(path)}:#{line}"
id = "#{File.basename(path)}:#{line} #{SecureRandom.hex}"
rule = rule_class.new(id, {}) do
describe(*args, &block)
end

View file

@ -22,21 +22,32 @@ describe Inspec::ProfileContext do
load('print os[:family]').must_output 'ubuntu'
end
it 'must profide file resource' do
it 'must provide file resource' do
load('print file("").type').must_output 'unknown'
end
it 'must profide command resource' do
it 'must provide command resource' do
load('print command("").stdout').must_output ''
end
it 'provides the describe keyword in the global DSL' do
load('describe true do; it { should_eq true }; end')
.must_output ''
profile.rules.keys.must_equal ['unknown:1']
profile.rules.keys.length.must_equal 1
profile.rules.keys[0].must_match /^unknown:1 [0-9a-f]+$/
profile.rules.values[0].must_be_kind_of Inspec::Rule
end
it 'loads multiple computed calls to describe correctly' do
load("%w{1 2 3}.each do\ndescribe true do; it { should_eq true }; end\nend")
.must_output ''
profile.rules.keys.length.must_equal 3
[0, 1, 2].each do |i|
profile.rules.keys[i].must_match /^unknown:2 [0-9a-f]+$/
profile.rules.values[i].must_be_kind_of Inspec::Rule
end
end
it 'does not provide the expect keyword in the global DLS' do
load('expect(true).to_eq true').must_raise NoMethodError
end