Unfinished Development Web Development, Infrastructure & Testing

Debugging with Puppet RSpec

Often it is useful to be able to run Puppet with verbose output during the execution of your specs. This is simple enough by adding the following to your spec or spec_helper.rb:

Puppet::Util::Log.level = :debug

However, adding and removing this everytime you need to switch verbose output on will quickly become a pain. The simple way around this is to add a conditional around the code to check for an environment variable:

  Puppet::Util::Log.level = :debug

Now, if you need to switch on verbose output, you just pass in the DEBUG environment variable when running your specs:

DEBUG=true bundle exec rspec spec/classes/your_spec.rb

Or with Rake:

DEBUG=truebundle exec rake spec