我正在测试一个资源,我想检查它是否有正确的参数数量,但其中一个是require,我还没有弄清楚如何在with中匹配它。我使用that_requires测试了该关系是否正确。我当前的测试看起来像这样
context 'xldeploy_environment_member' do
env = "Environments/#{company_short}/#{environment_short}/#{sn_environment}"
name = "#{env}/#{website}"
dict = "#{env}/dict.#{website}"
infhost = "Infrastructure/IIS/#{hostname}"
it { is_expected.to contain_xldeploy_environment_member(name).with({
:id => name,
:ensure => 'present',
:env => name,
:dictionaries => [dict],
:members => ["#{infhost}/#{website}", infhost],
}.merge($xldeploy_defaults))}
it { is_expected.to contain_xldeploy_environment_member(name).that_requires(
"Xldeploy_ci[#{name}]")
}
end但是我想用only_with替换with,因为with允许在没有相应测试的情况下添加额外的参数。如果有像resource_count这样的parameter_count检查,我可以使用它。rspec-puppet是否支持匹配正则表达式,以便我可以检查参数是否存在?我对实际内容不感兴趣,因为这是由that_requires测试的。
发布于 2017-08-18 09:15:02
是的,Rspec-puppet支持正则表达式,如果你想说“需要任何东西”与only_with结合,你可以这样写:
it {
is_expected.to contain_foo('bar').only_with({
'param1' => 'val1',
'param2' => 'val2',
'require' => //,
})
}https://stackoverflow.com/questions/45734764
复制相似问题