Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix construction of ruby objects on string and array handlers #746

Merged
merged 1 commit into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/inspec/objects/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions test/unit/objects_test.rb
Original file line number Diff line number Diff line change
@@ -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