【发布时间】:2020-04-09 02:54:45
【问题描述】:
是否有类似于 step_into 的方法来鼓励 Chefspec 遵循资源的 super 调用进入其父类?或者您能否建议一种方法来测试 super 调用是否按预期遵循(或未遵循),以在父类中执行适当的操作?
例如,
class Child < Chef::Provider::Parent
provides :child_resource
def action_create
# do childlike things
super
end
end
class Parent < Chef::Provider::LWRPBase
provides :parent_resource
def action_create
# do parental things
file "/home/mine/#{new_resource.name}.json" do
action :create
content 'I am malformed json content'
end
end
end
有配方
child_resource 'ima_potato' do
property 'vegechair'
end
并经过测试
require 'chefspec'
describe('procreate-concreate') do
let(:child_runner) do
memoized_runner('procreate-concreate', {step_into: ['child_resource', 'parent_resource']}, 'child_runner') do |node|
# node things
end
end
it 'creates the parent resource' do
expect(child_runner).to create_parent_resource('ima_potato')
end
it 'creates the parent file' do
expect(child_runner).to create_file('/home/mine/ima_potato.json')
end
end
上述模式有效。我的测试忽略了一个缺少的条件布尔值。
【问题讨论】: