fix construction of ruby objects on string and array handlers

This commit is contained in:
Dominik Richter 2016-05-13 18:53:20 +02:00
parent b837f8c8ec
commit 603e3e21b3
2 changed files with 57 additions and 1 deletions

View file

@ -49,7 +49,7 @@ module Inspec
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)

56
test/unit/objects_test.rb Normal file
View file

@ -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