我已经建立了一本安装 Jenkins CI 的食谱。它使用食谱中的key和repository资源yum,所以我最终得到以下食谱:
yum_key "RPM-GPG-KEY-jenkins" do
url "http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key"
action :add
end
yum_repository "jenkins" do
description "Jenkins-CI 3rd party repository"
url "http://pkg.jenkins-ci.org/redhat"
key "RPM-GPG-KEY-jenkins"
action :add
end
当我将此食谱包含在另一个食谱中时:
include_recipe 'sp_jenkins::default'
我使用以下 ChefSpec 测试对此进行了测试
it 'includes the `sp_jenkins::default` recipe' do
expect(chef_run).to include_recipe('sp_jenkins::install')
end
我的 ChefSpec 测试失败,输出如下:
NameError:
Cannot find a resource for yum_key on chefspec version 0.6.1
(我不确定为什么它说版本 0.6.1,gem list告诉我它使用的是 3.0.2)
sp_jenkins食谱确实依赖于yum食谱(metadata.rb),并且运行良好,但是,我目前正在编写的食谱不依赖于食谱yum,因此没有可用的yum_keyandyum_repository方法。
有没有办法防止 ChefSpec “下降”到包含的食谱/食谱中,而只是测试当前的食谱?