0

I am testing a resource and I want to check it has exactly the right number of parameters, but one of them is a require, which I haven't figured out how to match in a with. I test that the relationship is correct using that_requires. My current test looks like

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

but I would like to replace the with with an only_with, as the with would allow extra parameters to be added without a corresponding test. If there were a parameter_count check like there is a resource_count check I could use that. Does rspec-puppet support matching on regexes so that I can check that the parameter is there? I'm not interested in the actual content, as that is tested by the that_requires.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
smcp
  • 129
  • 2
  • 8
  • I believe you can chain `that_requires` onto a `with` chainer. Give it a try, and also see if you can chain it onto an `only_with` as metaparameters' matchers should not be covered in standard `with` chains. A couple other notes are that I don't think you need the `merge` in that code, and it also uses an undefined variable (assuming it is probably defined above the `context` block though), and that this test is testing hardcoded behavior, and you will see more interesting added value from testing dynamic input/output events. – Matthew Schuchard Aug 17 '17 at 15:38
  • Thanks I'll try the chaining. This is hardcoded because it is WIP. – smcp Aug 18 '17 at 10:57

1 Answers1

0

Yes, Rspec-puppet supports regexps, and if you want to say "require anything" in conjunction with only_with you could write:

  it {
    is_expected.to contain_foo('bar').only_with({
      'param1'  => 'val1',
      'param2'  => 'val2',
      'require' => //,
    })
  }
Alex Harvey
  • 14,494
  • 5
  • 61
  • 97