【发布时间】:2014-02-02 02:51:47
【问题描述】:
我正在尝试使用ChefSpec 测试角色。我宁愿不使用 Chef Zero(通过要求 'chefspec/server'),因为它的运行速度比 ChefSpec 本身的运行速度要慢一些。
也许我读错了文档,但似乎不需要 Chef Zero 来测试角色。但是,我目前的配置没有任何运气。这是我的测试:
require 'chefspec'
RSpec.configure do |config|
config.cookbook_path = 'C:\projects\chef\cookbooks'
config.role_path = 'C:\projects\chef\roles'
config.log_level = :debug
config.platform = 'ubuntu'
config.version = '12.04'
end
describe 'my_cookbook::default' do
let(:chef_run) do
ChefSpec::Runner.new.converge('role[my_role]')
end
it 'runs without failing' do
expect(chef_run)
end
end
角色(位于roles/my_role.json):
{
"name": "my_role",
"description": "My role",
"default_attributes": {
},
"run_list": [
"recipe[my_cookbook::default]"
]
}
当我运行测试时,我收到:
NoMethodError: undefined method `run_list_for' for #<Hash:0x4fa3280>
./spec/role_spec.rb:13:in `block (2 levels) in <top (required)>'
./spec/role_spec.rb:17:in `block (2 levels) in <top (required)>'
如果我修改我的测试以通过要求 chefspec/server 手动将角色加载到 Chef Zero 中,那似乎可行。我认为我不应该从编写文档的方式来模拟服务器,但我可能是错的。
我做错了吗?这是一个错误吗?还是我必须使用 Chef Zero?
【问题讨论】:
-
方法
run_list_for没有出现在 ChefSpec 或 Chef Zero 中。我可以看看你的方法吗? -
run_list_for(如果你指的是这个)不是我自己的方法,它似乎与厨师有关。堆栈跟踪在expect(chef_run)行上生成,默认配方本身为空。我能找到的唯一参考资料是一些与旧版本 chef solo(版本 10)相关的帖子,当 JSON 不包含特定属性值(如“json_class”:“Chef::Role”)时,它们会发出同样的异常。我添加了 JSON 内容,如果还有什么可以发布的内容,请告诉我。 -
什么版本的 ChefSpec?
-
spec/role_spec.rb 中的第 26 行是哪一行?错误所指的那个?
-
如果您将
"json_class":"Chef::Role"添加到您的角色会发生什么?
标签: chef-infra chefspec