I would like to add RSpec unit tests to some Puppet 4 modules. To get started and confirm basic functioning, I would first like to run unit tests that come with standard Puppet modules such as puppetlabs/apt.
If I try running a specific unit test like so
cd modules/apt
rspec spec/classes/apt_spec.rb
I get only failures, and some of the diagnostic output seems to indicate that part of the Puppet runtime environment (such as module stdlib, which defines function merge) was not picked up correctly:
Failures:
1) apt defaults should contain File[sources.list] that notifies Class[Apt::Update]
Failure/Error:
it { is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with({
:ensure => 'file',
:path => '/etc/apt/sources.list',
:owner => 'root',
:group => 'root',
:mode => '0644',
:notify => 'Class[Apt::Update]',
})}
Puppet::PreformattedError:
Evaluation Error: Unknown function: 'merge'. at /home/MY_USER/modules/apt/spec/fixtures/modules/apt/manifests/init.pp:50:14 on node MY_HOST
If I try running all unit tests like so
rake spec
I get this error message:
rake aborted!
NameError: uninitialized constant Bundler
/home/MY_USER/modules/apt/Rakefile:3:in `<top (required)>'
(See full trace by running task with --trace)
Prior to these attempts I have taken those steps to prepare the runtime environment (on a Debian host):
mkdir modules
cd modules
puppet module --modulepath=. install puppetlabs-apt # installs also stdlib
sudo gem install rspec-puppet
sudo gem install puppet
sudo gem install puppetlabs_spec_helper
sudo apt-get install rake
My question is this: How can I correctly prepare the runtime environment and successfully run the unit tests that come with a Puppet module from Puppet Forge such as puppetlabs/apt?