Information Technology Reference
In-Depth Information
require 'chefspec'
describe 'apache::default' do
chef_run = ChefSpec::Runner.new.converge('apache-test::default')
it 'installs apache2' do
expect(chef_run).to install_package('httpd')
end
end
Keep in mind that the preceding code is just runnable documentation. The expect statement
does not perform an httpd package installation during the in-memory Chef run. Instead,
ChefSpec merely performs the in-memory Chef run to verify the cookbook syntax; in this
case, to ensure that your code instructed Chef to install the package. This form of
documentation-based testing is good enough for well-tested Chef primitives, such as the
package resource.
Commands in ChefSpec are usually the results of an in-memory Chef run. ChefSpec match-
ers are documented[ChefSpec matchers] are documented as shown in Figure 16-18 .
Search WWH ::




Custom Search