diff --git a/lib/inspec/profile_context.rb b/lib/inspec/profile_context.rb index b001edfb4..247c92bf0 100644 --- a/lib/inspec/profile_context.rb +++ b/lib/inspec/profile_context.rb @@ -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 diff --git a/test/unit/profile_context_test.rb b/test/unit/profile_context_test.rb index c062e87b0..35f24d78a 100644 --- a/test/unit/profile_context_test.rb +++ b/test/unit/profile_context_test.rb @@ -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