mirror of
https://github.com/inspec/inspec
synced 2024-11-30 08:30:39 +00:00
Merge pull request #247 from chef/fix-describe-id
bugfix: support multiple computed calls to describe
This commit is contained in:
commit
f32d850618
2 changed files with 16 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
||||||
require 'inspec/rule'
|
require 'inspec/rule'
|
||||||
require 'inspec/dsl'
|
require 'inspec/dsl'
|
||||||
require 'rspec/core/dsl'
|
require 'rspec/core/dsl'
|
||||||
|
require 'securerandom'
|
||||||
|
|
||||||
module Inspec
|
module Inspec
|
||||||
class ProfileContext # rubocop:disable Metrics/ClassLength
|
class ProfileContext # rubocop:disable Metrics/ClassLength
|
||||||
|
@ -110,7 +111,7 @@ module Inspec
|
||||||
define_method :describe do |*args, &block|
|
define_method :describe do |*args, &block|
|
||||||
path = block.source_location[0]
|
path = block.source_location[0]
|
||||||
line = block.source_location[1]
|
line = block.source_location[1]
|
||||||
id = "#{File.basename(path)}:#{line}"
|
id = "#{File.basename(path)}:#{line} #{SecureRandom.hex}"
|
||||||
rule = rule_class.new(id, {}) do
|
rule = rule_class.new(id, {}) do
|
||||||
describe(*args, &block)
|
describe(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,21 +22,32 @@ describe Inspec::ProfileContext do
|
||||||
load('print os[:family]').must_output 'ubuntu'
|
load('print os[:family]').must_output 'ubuntu'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'must profide file resource' do
|
it 'must provide file resource' do
|
||||||
load('print file("").type').must_output 'unknown'
|
load('print file("").type').must_output 'unknown'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'must profide command resource' do
|
it 'must provide command resource' do
|
||||||
load('print command("").stdout').must_output ''
|
load('print command("").stdout').must_output ''
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'provides the describe keyword in the global DSL' do
|
it 'provides the describe keyword in the global DSL' do
|
||||||
load('describe true do; it { should_eq true }; end')
|
load('describe true do; it { should_eq true }; end')
|
||||||
.must_output ''
|
.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
|
profile.rules.values[0].must_be_kind_of Inspec::Rule
|
||||||
end
|
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
|
it 'does not provide the expect keyword in the global DLS' do
|
||||||
load('expect(true).to_eq true').must_raise NoMethodError
|
load('expect(true).to_eq true').must_raise NoMethodError
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue