在这里,我在变量中返回提供者的状态,如何在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
答案 0 :(得分:1)
我怀疑这是否有效,ret.update_by_last_action?
在提供商没有运行的编译时进行评估。
建议的方法是使用notifications,如下所示:
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
然后你可以期待notification is sent并创建文件。
规范示例:
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')