How can I test "super" in a Chef resource?

37 Views Asked by At

Is there an approach similar to step_into to encourage Chefspec to follow a resource's super call into its parent class? Or can you suggest an approach to test that the super call is followed (or not followed) as expected, to perform the appropriate action in the parent class?

e.g.,

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

with recipe

child_resource 'ima_potato' do
  property 'vegechair'
end

and tested with

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

The above pattern works. My testing overlooked a missing boolean for a conditional.

1

There are 1 best solutions below

0
Sarai On

The above pattern works. My testing overlooked a missing boolean for a conditional.