在这里,我在变量中返回提供者的状态,如何在 chefspec 中模拟该状态以进行测试?
ret = yum_package 'blah' do
action :install
end
cookbook_file "/etc/init.d/blah" do
source "blah"
only_if { ret.updated_by_last_action? }
end
在这里,我在变量中返回提供者的状态,如何在 chefspec 中模拟该状态以进行测试?
ret = yum_package 'blah' do
action :install
end
cookbook_file "/etc/init.d/blah" do
source "blah"
only_if { ret.updated_by_last_action? }
end
我怀疑这项工作,ret.update_by_last_action?
在提供程序未运行时在编译时进行评估。
推荐的方法是使用这样的通知:
yum_package 'blah' do
action :install
notifies :create,"cookbook_file[/etc/init.d/blah]", :immediately
end
cookbook_file "/etc/init.d/blah" do
action :nothing
source "blah"
end
然后您可以预期会发送通知并创建文件。
规格示例:
blah_package = chef_run.yup_package('blah')
expect(blah_package).to notify('cookbook_file[/etc/init.d/blah]').to(:create).immediately
expect(chef_run).to render_file('/etc/init.d/blah')