Ruby 如何在Inspec中的http块中使用字符串连接?
我有一个包含http块的Inspec控件。URL保存在名为Ruby 如何在Inspec中的http块中使用字符串连接?,ruby,chef-infra,inspec,Ruby,Chef Infra,Inspec,我有一个包含http块的Inspec控件。URL保存在名为DNScloudui['value']的变量中-我想将https://添加到URL的开头 DNScloudui = attribute('DNS_name_cloudui') control 'Website reachability' do title 'Check reachability by GET requests' describe http(DNScloudui['value'], method: 'GET') d
DNScloudui['value']
的变量中-我想将https://
添加到URL的开头
DNScloudui = attribute('DNS_name_cloudui')
control 'Website reachability' do
title 'Check reachability by GET requests'
describe http(DNScloudui['value'], method: 'GET') do
its('status') { should cmp 200 }
end
end
如何实现这一点?假设
DNScloudui
返回非零值,则可以使用字符串插值来获取DNScloudui
变量的值。例如:
DNScloudui = attribute('DNS_name_cloudui')
control 'Website reachability' do
title 'Check reachability by GET requests'
describe http("https://#{DNScloudui['value']}", method: 'GET') do
its('status') { should cmp 200 }
end
end
另外,看一下您的
DNScloudui
变量的名称,我建议坚持使用而不是像“https//{DNScloudui['value']}”
那样的插值工作?不(未终止的regexp与文件结尾(SyntaxError))DNScloudui的值是多少?或者DNScloudui=“https://{attribute('DNS_name_cloudui')}“
,如果这不起作用,那么上面的注释肯定是相关的。DNScloudui的值是这样的:“foo.bar.foo bar.com”