From 603e3e21b3a9a948c9a802f3d55d44ee06f793fb Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Fri, 13 May 2016 18:53:20 +0200 Subject: [PATCH] fix construction of ruby objects on string and array handlers --- lib/inspec/objects/test.rb | 2 +- test/unit/objects_test.rb | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/unit/objects_test.rb diff --git a/lib/inspec/objects/test.rb b/lib/inspec/objects/test.rb index 43fba238b3..3022a7c12c 100644 --- a/lib/inspec/objects/test.rb +++ b/lib/inspec/objects/test.rb @@ -49,7 +49,7 @@ def describe_chain if @qualifier.length > 1 last = @qualifier[-1] # preventing its('to_i') as the value returned is always 0 - if last.length == 1 && last[0] != 'to_i' + if last.length == 1 && last[0] !~ /^to_.$/ && !last[0].include?('[') xres = last[0] else res += '.' + ruby_qualifier(last) diff --git a/test/unit/objects_test.rb b/test/unit/objects_test.rb new file mode 100644 index 0000000000..fb82c39cfe --- /dev/null +++ b/test/unit/objects_test.rb @@ -0,0 +1,56 @@ +# encoding: utf-8 +# author: Dominik Richter +# author: Christoph Hartmann + +require 'helper' +require 'inspec/objects' + +describe 'Objects' do + describe 'Test' do + let(:obj) { Inspec::Test.new } + it 'constructs a simple resource+argument' do + obj.qualifier = [['resource'], ['arg']] + obj.to_ruby.must_equal " +describe resource do + its(\"arg\") { should } +end +".strip + end + + it 'constructs a simple resource+argument with to_s' do + obj.qualifier = [['resource'], ['to_s']] + obj.to_ruby.must_equal " +describe resource.to_s do + it { should } +end +".strip + end + + it 'constructs a simple resource+argument with to_i' do + obj.qualifier = [['resource'], ['to_i']] + obj.to_ruby.must_equal " +describe resource.to_i do + it { should } +end +".strip + end + + it 'constructs a simple resource+argument with array accessors' do + obj.qualifier = [['resource'], ['name[2]']] + obj.to_ruby.must_equal " +describe resource.name[2] do + it { should } +end +".strip + end + + it 'constructs a simple resource+argument with method calls' do + obj.qualifier = [['resource'], ['hello', 'world']] + obj.to_ruby.must_equal " +describe resource.hello(\"world\") do + it { should } +end +".strip + end + end +end