in trying to write chefspec tests, following the examples on the chefspec README (https://github.com/acrmp/chefspec), I get the following error. I tried adding "depends 'chef_handler'" to my metadata.rb, without success:
$ bundle exec rspec
*[2013-08-15T11:55:01-07:00] WARN: found a directory cookbooks in the cookbook path, but it contains no cookbook files. skipping.
F*
Pending:
example::default should include
# Your recipe examples go here.
# ./spec/default_spec.rb:6
example::single_node should do something
# Your recipe examples go here.
# ./spec/single_node_spec.rb:5
Failures:
1) example::default logs the foo attribute
Failure/Error: chef_run.converge 'example::default'
Chef::Exceptions::CookbookNotFound:
Cookbook chef_handler not found. If you're loading chef_handler from another cookbook, make sure you configure the dependency in your metadata
# ./spec/default_spec.rb:16:in `block (2 levels) in <top (required)>'
I had the same problem trying to test a custom Chef handler, but I was trying to use Berkshelf to pull dependencies down via ChefSpec's native support for Berkshelf. Here's what worked for me:
Add a spec/spec_helper.rb with
require 'chefspec'
require 'chefspec/berkshelf'
Add a .rspec file to the root of the cookbook project with
--color
--format progress
--require spec_helper
Ensure your spec (spec/default_spec.rb) is setup correctly
describe 'my_chef_handlers::default' do
handler_path = File.join('files', 'default')
let(:chef_run) do
chef_runner = ChefSpec::Runner.new do |node|
node.set['chef_handler']['handler_path'] = handler_path
node.set['statsd']['server'] = '127.0.0.1'
end
chef_runner.converge 'my_chef_handlers::default'
end
end
Setting up the ChefSpec runner outside the let statement caused cookbook not found errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With