【问题标题】:How can I test "super" in a Chef resource?如何在 Chef 资源中测试“超级”?
【发布时间】: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

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

【问题讨论】:

    标签: super chefspec


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      • 2015-08-12
      • 1970-01-01
      • 2015-12-19
      • 2020-08-13
      • 2014-04-01
      相关资源
      最近更新 更多