如何在 Chef 资源中测试"super"?



是否有类似于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

上述模式有效。我的测试忽略了一个条件的布尔值。

以上模式有效。我的测试忽略了一个条件的布尔值。

最新更新