0

我正在测试一个资源,我想检查它的参数数量是否正确,但其中一个是 a require,我还没有弄清楚如何在 a 中匹配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

但我想用 替换withonly_with因为这with将允许在没有相应测试的情况下添加额外的参数。如果有一张parameter_count支票,比如有一张resource_count支票,我可以使用它。是否rspec-puppet支持正则表达式匹配,以便我可以检查参数是否存在?我对实际内容不感兴趣,因为这是由that_requires.

4

1 回答 1

0

是的,Rspec-puppet 支持正则表达式,如果你想说“需要任何东西”,only_with你可以写:

  it {
    is_expected.to contain_foo('bar').only_with({
      'param1'  => 'val1',
      'param2'  => 'val2',
      'require' => //,
    })
  }
于 2017-08-18T01:15:01.653 回答