There’s a growing movement for testing chef cookbooks, which is great to see. I haven’t gotten to play with them all, but some that I’ve come across are the minitest chef handler, chefspec, and cucumber-chef.
The lowest hanging fruit however is linting, which is where foodcritic comes in. Foodcritic parses your cookbook, and warns you about many common errors.
Food critic will yell at you about all sorts of things – if you are accessing node attributes inconsistently, if you’re passing valid ruby as a not_if string, if you’re using /tmp instead of file_cache_path, and many more. For a full list, see the github pages
Automatically running foodcritic on your public cookbooks is easy with Travis CI. Just add a .travis.yml to your repo that looks like this:
script: "gem install foodcritic -v 1.1.0 && foodcritic -f any ." rvm: - 1.9.3
And follow the travis getting started guide. You’ll then get an email if you commit something that isn’t quite up to par.
You can see a pivotal_workstation run on travis. We’ve still got a little ways to go to get to green, but everything it’s telling us are things we’d like to do. (pull requests welcome!)