Module: ChefSpec::API::BatchMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a batch resource exists in the Chef run with the action :run. Given a Chef Recipe that runs “unzip” using batch:

batch 'unzip' do
  action :run
end

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

Examples:

Assert that a batch was run

expect(chef_run).to run_batch('unzip')

Assert that a batch was run with predicate matchers

expect(chef_run).to run_batch('unzip').with_cwd('/home')

Assert that a batch was run with attributes

expect(chef_run).to run_batch('unzip').with(cwd: '/home')

Assert that a batch was run using a regex

expect(chef_run).to run_batch('unzip').with(cwd: /\/(.+)/)

Assert that a batch was not run

expect(chef_run).to_not run_batch('unzip')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



39
40
41
# File 'lib/chefspec/api/batch.rb', line 39

def run_batch(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:batch, :run, resource_name)
end