Unit testing with ChefSpec

Now that we have cookbooks that are adhering to the best practices of both Ruby and Chef, it is time to turn our attention away from static analysis and toward runtime testing. This is where we begin to move from a model of cookbooks-as-code to one of cookbooks-as-artifacts. Unit testing is a kind of middle ground, where we are doing a combination of code testing and artifact testing. This is also the point at which we move into a test-driven development model, where you write the tests before you write the code.

Ruby is a dynamically typed language. Ruby code is not type checked until it is executed. So in order to actually test our cookbooks, they have to be run. Before ChefSpec, this meant that you had to make the ...

Get Mastering Chef Provisioning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.