Verify Your Chef Infrastructure With Minitest

This is the tenth, and final post, in a series on the development of Chef Broiler Plate in which we go over setting up a robust, TED framework for Chef cookbook development.

The last adventure on this journey will be to set up the mini test suite to verify our cookbooks on a real server, not just the specs in a vacuum. We will do this with minitest, by way of the mini test handler, that we set up in our last post by using the Berkshelf cookbook manager.

Put your Files Somewhere!

The files need to be in the right place, so let's add the defaults to our existing cookbook:

mkdir -p cookbooks/motd/files/default/tests/minitest
touch cookbooks/motd/files/default/tests/minitest/default_test.rb

In order to prevent ever having to do this heinous act again, let's modify the new_cookbook Rake task to make this part of the cookbook buildout:

desc "Creates a new cookbook."
task :new_cookbook, :name do |t, args|
  sh "bundle exec knife cookbook create #{}"
  sh "bundle exec knife cookbook create_specs #{}"
  minitest_path = "cookbooks/#{}/files/default/tests/minitest"
  mkdir_p minitest_path"#{minitest_path}/default_test.rb", 'w') do |test|
    test.puts "require 'minitest/spec'"
    test.puts "describe_recipe '#{}::default' do"
    test.puts "end"

This now creates a basic minitest that can be modified to your hearts content.

Building the Test

Our test is pretty simple for this cookbook and I just want to assert that the file was created:

require 'minitest/spec'
describe_recipe 'motd::default' do
    it 'creates motd.tail' do

Deploying the Cookbook and Testing

I bump the version of my cookbook and provision the server. Turns out, it works like a charm.

recipe::motd::default#test_0001_creates_motd_tail =
0.00 s =

Finished tests in 0.007227s, 276.7214 tests/s, 138.3607 assertions/s.

2 tests, 1 assertions, 0 failures, 0 errors, 0 skips

Not only do these act as integration tests, ensuring you have built cookbooks that really work when used on the servers, but they also act as a safety net as they are run whenever the server is provisioned. If for any reason some other cookbook conflicts or an error occurs, you will know about it.


I hope that those who followed this series have learned a bunch on how to build cookbooks in a true, test-driven way. I encourage you to check out the Chef Broiler Plate repository, and also the book: The Chef Survival Guide. I'll summarize the ways to test Chef Cookbooks in a future post. Best of luck with your automated infrastructure adventures!

If you enjoyed reading this or learned something, please consider sharing via , , or . Thanks!