ChefSpec Chef Tool
ChefSpec is a unit-testing framework for Chef cookbook. It allows you to write RSpec examples and generate coverage reports for Chef recipes!
Install & Usage Instructions
ChefSpec is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.
ChefSpec runs your cookbook locally using Chef Solo without actually converging a node. This has two primary benefits:
- It's really fast!
- Your tests can vary node attributes, operating systems, and search results to assert behavior under varying conditions.
Writing a Cookbook Example
If you want knife
to automatically generate spec stubs for you, install knife-spec.
Given an extremely basic Chef recipe that just installs an operating system package:
package 'foo'
the associated ChefSpec test might look like:
require 'chefspec' describe 'example::default' do let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'installs foo' do expect(chef_run).to install_package('foo') end end