杂散 ruby 变量的 chefspec 测试
chefspec testing for stray ruby variable
在这里,我在变量中返回提供者的状态,我如何在 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?
是在编译时计算的,而提供者没有 运行。
推荐的方法是像这样使用 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')
在这里,我在变量中返回提供者的状态,我如何在 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?
是在编译时计算的,而提供者没有 运行。
推荐的方法是像这样使用 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')