mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
fix construction of ruby objects on string and array handlers
This commit is contained in:
parent
b837f8c8ec
commit
603e3e21b3
2 changed files with 57 additions and 1 deletions
|
@ -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
56
test/unit/objects_test.rb
Normal 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
|
Loading…
Reference in a new issue