gpt4 book ai didi

unit-testing - 为什么 chefspec 找不到 chef_handler Recipe ?

转载 作者:行者123 更新时间:2023-11-28 19:51:06 25 4
gpt4 key购买 nike

在尝试编写 chefspec 测试时,按照 chefspec 自述文件 (https://github.com/acrmp/chefspec) 中的示例,我收到以下错误。我尝试将“depends '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*

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)>'

最佳答案

我在尝试测试自定义 Chef 处理程序时遇到了同样的问题,但我试图使用 Berkshelf 通过 ChefSpec 对 Berkshelf 的 native 支持来降低依赖性。这是对我有用的:

添加 spec/spec_helper.rb

require 'chefspec'
require 'chefspec/berkshelf'

将 .rspec 文件添加到 cookbook 项目的根目录中

--color
--format progress
--require spec_helper

确保您的规范 (spec/default_spec.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 错误。

关于unit-testing - 为什么 chefspec 找不到 chef_handler Recipe ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18260034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com