alexharv074.github.io

My blog

View on GitHub
16 March 2016

Dumping the catalog in rspec-puppet

by Alex Harvey

I always knew there must be a better way.

In a previous post I documented a procedure for compiling a catalog without logging onto a Puppet Master. The procedure is useful but also complicated.

I often wondered why Rspec-puppet couldn’t just dump the catalogs it compiles during unit testing.

Well it can; I just found a bit of the answer here, and the rest inside the debugger.

How to dump the catalog in Rspec-puppet

I assume we have Rspec-puppet set up already. If not, try the Rspec-puppet tutorial.

Imagine we have a simple test as follows:

require 'spec_helper'

describe 'myclass' do
  it {
    is_expected.to compile.with_all_deps
  }
end

To instead just dump the catalog, change the code as follows:

require 'spec_helper'

describe 'myclass' do
  it {
    File.write(
      'myclass.json',
      PSON.pretty_generate(catalogue)
    )
    #is_expected.to compile.with_all_deps
  }
end

Note carefully the use of UK spelling in ‘catalogue’. Otherwise, that’s it. Now run the spec tests again and you’ll have the catalog under test saved in myclass.json.

Update see also Rob Nelson’s related post here.

tags: puppet - catalog - rspec