Running catalogs from RSpec tests is tricky. There are some examples in the existing test base that help doing it. One basic pattern goes like this:
Of course, such tests can fail for various reasons. The test environment
can be incredibly fragile at times. But since all the interesting things
happen in the catalog.apply
method, it’s difficult to probe into it
without resorting to pry and friends.
Fortunately, Puppet’s RSpec suite is set up
to collect all log output in the special member variable @logs
.
The easiest way (that I know of) to examine this data in a failing test
is temporarily raising it as an exception.
When this test is run, it will fail due to the unexpected exception,
dumping the exception details on the terminal. These details consist
of the Puppet output as produced when applying the catalog. It closely
resembles the output of puppet agent
or puppet apply
. A very good
first step for debugging this kind of test.