Allan Espinosa

Really unit testing Chef recipes

2014 June 29


  • Simple to get started
  • Build the resource collection
  • Monkeypatch a provider’s :perform_action method to do nothing.
  • More complete
  • A lot of monkey patching on assertions

Unit testing recipes

  • You want to assert the resource collection after compiling the recipe. Borrowed from the description of rspec-puppet.
  • if else logic
  • Need to stub the whole chef
    • run_context
    • node object

Test according to the Chef run cycle. An overview from Actual code is in

Fake that in the run context. So do that in the unit test as well to stub the run_context


  • Fast tests
  • really isolated recipes
  • understanding of chef’s innards


  • too much to stub
  • Reflects on the design of chef?
  • Are the tests here telling us something?