0

Obligatory sorry if I'm being a noob but... I'm pretty new to rspec/ruby etc and I'm struggling to figure a few things out. Given the following rspec-puppet snippet:

if os == 'Ubuntu'
  let(:facts) do
    {
      architecture: 'amd64',
      operatingsystem: 'Ubuntu',
    }
  end

  it { is_expected.to contain_service('docker').with_hasrestart('true') }

  context 'It should include default prerequired_packages' do
    it { is_expected.to contain_package('cgroup-lite').with_ensure('present') }
    it { is_expected.to contain_package('apparmor').with_ensure('present') }
  end
end

We've got these functions(objects?) like contain_service() and contain_package() that seem to have methods like with_hasrestart and with_ensure. What I'm trying to understand is, what are these functions? Are they part of rspec-puppet? I can't seem to find them in GitHub, and the docs don't really explain it. I'm trying to find all the available methods for each to better understand this all - and the source code would be great. Can anyone offer up some info/docs that explain it please?

Many thanks,

Dave

Edit: Looks like I didn't RTFM enough. It appears these are "matchers" and searching for contain_package in the code would never work.

dwjv
  • 1,227
  • 9
  • 15
  • Those are matchers, you might have some kind of gem that is providing them... – Greg Jul 08 '20 at 12:03
  • yeah, think I'm starting to understand it now: https://github.com/rodjek/rspec-puppet/blob/master/lib/rspec-puppet/matchers/create_generic.rb – dwjv Jul 08 '20 at 12:04

1 Answers1

0

Answering my own post, but I doubt anyone will actually need this.

These are "matchers", specifically a generic one here. They're part of the rspec-puppet package: https://github.com/rodjek/rspec-puppet/blob/master/lib/rspec-puppet/matchers/create_generic.rb

You can essentially do contain_<puppet resource> and those methods like with_ensure are like with_<resource parameter>.

dwjv
  • 1,227
  • 9
  • 15