Testing your Chef cookbooks with cookstyle and Rubocop
You know how annoying this is: you tweak a cookbook, run Test Kitchen, and, boom! it fails. What's even more annoying is that it fails only because you missed a mundane comma in the default recipe of the cookbook you just tweaked. Fortunately, there's a very quick and easy way to find such simple glitches before you go all in and try to run your cookbooks on Test Kitchen.
Getting ready
Install the ntp
cookbook by running the following command:
mma@laptop:~/chef-repo $ knife cookbook site install ntp Installing ntp to /Users/mma/work/chef-repo/cookbooks …TRUNCATED OUTPUT… Cookbook ntp version 3.2.0 successfully installed
How to do it…
Carry out the following steps to test your cookbook; run cookstyle
on the ntp
cookbook:
mma@laptop:~/chef-repo $ cookstyle cookbooks/ntp Inspecting 5 files ...C. Offenses: cookbooks/ntp/recipes/default.rb:25:1: C: Extra blank line detected. 5 files inspected, 1 offense detected
How it works…
Cookstyle
is...