From 3afd0d556d6db16d426d9ca5685718ad683ec36f Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 19 Nov 2015 14:17:18 +0100 Subject: [PATCH 1/3] fix typos Signed-off-by: Dominik Richter --- test/unit/profile_context_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/profile_context_test.rb b/test/unit/profile_context_test.rb index c062e87b0..124805671 100644 --- a/test/unit/profile_context_test.rb +++ b/test/unit/profile_context_test.rb @@ -22,11 +22,11 @@ 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 From d9ded1d38d0642ee1a49c2a872ff1add33dc53e0 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 19 Nov 2015 14:22:42 +0100 Subject: [PATCH 2/3] test for multiple computed calls to flat describe --- test/unit/profile_context_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/unit/profile_context_test.rb b/test/unit/profile_context_test.rb index 124805671..35f24d78a 100644 --- a/test/unit/profile_context_test.rb +++ b/test/unit/profile_context_test.rb @@ -33,10 +33,21 @@ describe Inspec::ProfileContext do 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 From a04ff021c6ebfb1a502b124ad2db4a3097d975b5 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 19 Nov 2015 14:24:46 +0100 Subject: [PATCH 3/3] bugfix: support multiple computed calls to describe fixes #246 --- lib/inspec/profile_context.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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