Unit testing 为什么可以';chefspec找到厨师长的食谱了吗?
在尝试编写chefspec测试时,按照chefspec README()上的示例,我得到了以下错误。我尝试将“依赖‘chef_handler’”添加到我的metadata.rb中,但没有成功:Unit testing 为什么可以';chefspec找到厨师长的食谱了吗?,unit-testing,testing,chef-infra,Unit Testing,Testing,Chef Infra,在尝试编写chefspec测试时,按照chefspec README()上的示例,我得到了以下错误。我尝试将“依赖‘chef_handler’”添加到我的metadata.rb中,但没有成功: $ 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*
$ 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)>'
$bundle exec rspec
*[2013-08-15T11:55:01-07:00]警告:在cookbook路径中找到cookbooks目录,但它不包含cookbook文件。跳过
F*
悬而未决的:
示例::默认值应包括
#你的食谱例子在这里。
#/规格/默认规格rb:6
示例::单_节点应该做一些事情
#你的食谱例子在这里。
#/规格/单节点规格rb:5
失败:
1) 示例::默认记录foo属性
失败/错误:chef_run.converge“示例::默认”
厨师长::例外::CookbookNotFound:
找不到Cookbook chef_handler。如果要从另一本烹饪书加载chef_处理程序,请确保在元数据中配置依赖项
#./spec/default_spec.rb:16:in'block(2层)in'
我最近遇到了同样的问题。因为chefspec的目标是快速,并且只模拟厨师运行,所以它不会从厨师服务器克隆食谱。它要求食谱必须是本地的。默认情况下,它在与您正在测试的烹饪书相同的级别上查找它
e、 g
我在尝试测试自定义Chef处理程序时遇到了同样的问题,但我试图通过ChefSpec对Berkshell的本机支持,使用Berkshell来下拉依赖项。以下是对我有效的方法: 使用添加等级库/spec\u helper.rb
require 'chefspec'
require 'chefspec/berkshelf'
使用将.rspec文件添加到cookbook项目的根目录中
--color
--format progress
--require spec_helper
确保您的等级库(等级库/默认等级库.rb)设置正确
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
在let语句之外设置ChefSpec runner会导致cookbook not found错误
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