首页 > 解决方案 > 如何在 Chef 资源中测试“超级”?

问题描述

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

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

标签: superchefspec

解决方案


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


推荐阅读