Module: ChefSpec::API::ExecuteMatchers

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

Overview

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

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

Assert that an execute resource exists in the Chef run with the action :run. Given a Chef Recipe that runs “echo ”hello“” as an execute:

execute 'echo "hello"' do
  action :run
end

The Examples section demonstrates the different ways to test an execute resource with ChefSpec.

Examples:

Assert that an execute was runed

expect(chef_run).to run_execute('echo "hello"')

Assert that an execute was runed with predicate matchers

expect(chef_run).to run_execute('echo "hello"').with_user('svargo')

Assert that an execute was runed with attributes

expect(chef_run).to run_execute('echo "hello"').with(user: 'svargo')

Assert that an execute was runed using a regex

expect(chef_run).to run_execute('echo "hello"').with(user: /sva(.+)/)

Assert that an execute was not runed

expect(chef_run).to_not run_execute('echo "hello"')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1



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

def run_execute(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:execute, :run, resource_name)
end