rspec question: how to test that no resource exists with certain parameters?

81 views
Skip to first unread message

johnso...@gmail.com

unread,
Jul 20, 2015, 3:28:44 PM7/20/15
to puppet...@googlegroups.com
RSpec question for all the helpful folks here:

How do I test that there is no resource in the catalog that matches certain parameters?

I know how to test that a specific resource does not exist, or a specific resource does not match certain parameters.

I want to test that, for example, there are no file resources with :ensure => directory set.

Is this possible?

Thanks in advance,
- Johnson

Hunter Haugen

unread,
Jul 20, 2015, 4:30:14 PM7/20/15
to puppet...@googlegroups.com
There is no helper built in to rspec-puppet to do this, but you can do it by using an rspec expect() around a catalogue.resources check:

it "has no file resources with ensure => directory" do
  expect(catalogue.resources.select { |r| r.type == "File" && r[:ensure] == "directory" }).to be_empty
end

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/89c69357-d468-47ec-80ca-50f847a24a24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johnson Earls

unread,
Jul 20, 2015, 8:27:24 PM7/20/15
to puppet...@googlegroups.com
Thanks, I'll try that.
- Johnson
Reply all
Reply to author
Forward
0 new messages