如何将属性从文件加载到 chefspec 节点

How to load attributes from a file to chefspec node

我有以下布局:

attributes/default.rb
recipes/my_recipe.rb
spec/unit/recipes/my_recipe_spec.rb

在属性文件中我有很多常用的设置喜欢

default['framework']['folder']['lib'] = '/usr/lib/fwrk'

我想在我的 chefspec 中使用它们,例如

it 'install the lib if there are changes' do
    lib_path = chef_run.node['framework']['folder']['lib']
    puts(lib_path)
end

如何从 SoloRunner/ServerRunner 将此文件包含到我的节点中?

运行 首先是 .converge(),您会在那里看到它们。但是请记住,您几乎总是在两侧的相同输入上对测试进行参数化,这不是一个有用的测试,因为它不会检查值是否符合您的预期。