Why can't chefspec find the chef_handler cookbook?

when I try to write chefspec tests, following the examples on chefspec README ( https://github.com/acrmp/chefspec ), I get the following error. I tried adding "depends on chef_handler" to my .rb metadata, 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)>' 
+4
source share
2 answers

I recently ran into the same problem. Since chefspec strives to be fast and only mimics the work of a chef, he does not clone cookbooks from the chef's server. This requires that the chef_handler table must be local. By default, he searches for it at the same level as the cookbook you are testing.

eg.

 ./test_cookbook ./chef_handler 
+1
source

I had the same problem trying to test a custom Chef handler, but I tried to use Berkshelf to pull dependencies using the built-in ChefSpec support for Berkshelf. Here is what worked for me:

Add spec / spec_helper.rb with

 require 'chefspec' require 'chefspec/berkshelf' 

Add the .rspec file to the root of the cookbook project with

 --color --format progress --require spec_helper 

Make sure your spec (spec / default_spec.rb) is configured 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 the cookbook to fail to find errors.

+8
source

Source: https://habr.com/ru/post/1497305/


All Articles