If you've worked with configuration management systems for a while, a situation
like this has probably cropped up and ruined your day. If you're lucky
enough to have a homogeneous environment, then you might have a staging
environment that you can test changes out on, but what if you don't? A slight
mistake in that harmless change you're working on could stop a service on
hundreds of machines or worse (purge the mysql-server package and all it's data
*cough*).

Why you should be writing unit tests for your Puppet modules

Prevent situations like the one above.

Catch any problems moving between Puppet releases before it hits production.

Now we can do this too

Getting started

In this article, we'll cover setting up your testing environment and cover how
to write unit tests for your Puppet functions. I'm going to make a few
assumptions now:

You store your Puppet manifests in git.

You run a *nix machine as your workstation.

You don't mind getting your hands dirty with a bit of simple Ruby.

You have Ruby installed (1.8.7).

First of all, we're going to install Bundler to manage
the dependencies our Puppet testing rig will have.

OK, time to configure RSpec. Create
a spec directory in the root of your Puppet repository and create a file in
the spec folder called spec_helper.rb. Adjust c.module_path and
c.manifest_dir to point to your modules and manifests directories in your
repository.