Chef cookbook linting with foodcritic

April 11, 2012 Matthew Kocher

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 ."
  - 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!)

About the Author


Cloud Foundry’s First Birthday: More Clouds, Code, Community and Partners
Cloud Foundry’s First Birthday: More Clouds, Code, Community and Partners

Today we celebrated Cloud Foundry’s first anniversary with additional multi-cloud deployment choices, new t...

iOS Roundup: April 9, 2012
iOS Roundup: April 9, 2012

Cool Things This Week: Now instead of dealing with state variables on viewDidAppear, we can use a completi...

SpringOne 2021

Register Now