Testing your manifests with rspec-puppet
It would be great if we could verify that our Puppet manifests satisfy certain expectations without even having to run Puppet. rspec-puppet
is a nifty tool for doing this. Based on RSpec, a testing framework for Ruby programs, rspec-puppet
lets you write test cases for your Puppet manifests that are especially useful for catching regressions (bugs introduced when fixing another bug) and refactoring problems (bugs introduced when reorganizing your code).
Getting ready...
Here's what you'll need to do to install rspec-puppet
.
Run the following commands:
ubuntu@cookbook:~/puppet$ sudo gem install rspec-puppet ubuntu@cookbook:~/puppet$ sudo gem install puppetlabs_spec_helper
How to do it...
Let's write some tests for our admin::ntp
class.
Run the following commands:
ubuntu@cookbook:~/puppet$ cd modules/admin/ ubuntu@cookbook:~/puppet/modules/admin$ rspec-puppet-init + spec/ + spec/classes/ + spec/defines/ + spec/functions/ + spec/hosts/ + spec...