Information Technology Reference
In-Depth Information
case, the cautions are that ChefSpec::Coverage.report! must be run after all tests are
complete and not run more than once in a program. We use at_exit to ensure that report!
is run once after the tests have finished.
Example 16-14. chefdk/apache-test/spec/default_spec.rb
require 'chefspec'
at_exit { ChefSpec : :Coverage . report! }
describe 'apache-test::default' ddo
let ( :chef_run ) { ChefSpec : :Runner . new . converge ( described_recipe ) }
it 'installs apache2' ddo
expect ( chef_run ) . to install_package ( 'httpd' )
end
end
end
end
Run rspec --color with the new at_exit code, and notice that now a helpful report is
generated, telling you the total number of resources in your code and how many have been
tested in your specs:
$ rspec --color
.
Finished in 0.00337 seconds (files took 1.11 seconds to load)
1 example, 0 failures
ChefSpec Coverage report generated...
Total Resources: 3
Touched Resources: 1
Touch Coverage: 33.33%
Untouched Resources:
service[httpd] /recipes/default.rb:12
template[/var/www/html/index.html] /recipes/default.rb:16
Let this report guide you in choosing other tests to write for your code.
Search WWH ::




Custom Search