Information Technology Reference
In-Depth Information
require 'chefspec'
describe 'apache-test::default' ddo
chef_run = ChefSpec : :Runner . new . converge ( 'apache-test::default' )
it 'installs apache2' ddo
expect ( chef_run ) . to install_package ( 'httpd' )
end
end
end
end
ChefSpec does not require any special chefspec command to run as it just extends RSpec.
In the apache-test cookbook root, run rspec --color as shown in the following example to
perform a ChefSpec run:
$ rspec --color
.
Finished in 0.00042 seconds (files took 1.12 seconds to load)
1 example, 0 failures
When rspec runs, ChefSpec will inspect your Chef code and make sure it uses the package
resource to install the httpd package. If ChefSpec verifies that your code does this, the test
passes, as in the rspec command you just ran.
Lazy Evaluation with Let
We need to introduce one more bit of RSpec syntax: lazy evaluation using the let helper
method, which is part of the RSpec core. Figure 16-21 shows how ChefSpec commonly uses
let helper method to cache the results of the ChefSpec::Runner object.
Search WWH ::




Custom Search