Module: ChefSpec::API::DscResourceMatchers

Defined in:
lib/chefspec/api/dsc_resource.rb

Overview

Since:

  • 4.3.0

Instance Method Summary collapse

Instance Method Details

#run_dsc_resource(resource_name) ⇒ ChefSpec::Matchers::ResourceMatcher

Assert that a dsc_resource resource exists in the Chef run with the action :run. Given a Chef Recipe that installs “zip” as a dsc_resource:

dsc_resource 'zip' do
  resource :archive
  property :ensure, 'Present'
  property :path, "C:\Users\Public\Documents\example.zip"
  property :destination, "C:\Users\Public\Documents\ExtractionPath"
end

To test the content rendered by a dsc_resource, see RenderFileMatchers.

The Examples section demonstrates the different ways to test a dsc_resource resource with ChefSpec.

Examples:

Assert that a dsc_resource was installed

expect(chef_run).to run_dsc_resource('zip')

Assert that a dsc_resource was installed with predicate matchers

expect(chef_run).to run_dsc_resource('zip').with_resource(:archive)

Assert that a dsc_resource was installed with attributes

expect(chef_run).to run_dsc_resource('zip').with(resource: :archive)

Assert that a dsc_resource was installed using a regex

expect(chef_run).to run_dsc_resource('zip').with(resource: /:arch(.+)/)

Assert that a dsc_resource was not installed

expect(chef_run).to_not run_dsc_resource('zip')

Since:

  • 4.3.0



45
46
47
# File 'lib/chefspec/api/dsc_resource.rb', line 45

def run_dsc_resource(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:dsc_resource, :run, resource_name)
end