Module: ChefSpec::API::ScriptMatchers

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

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

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

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

bash 'command' do
  action :run
end

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

Examples:

Assert that a bash was run

expect(chef_run).to run_bash('command')

Assert that a bash was run with predicate matchers

expect(chef_run).to run_bash('command').with_cwd('/home')

Assert that a bash was run with attributes

expect(chef_run).to run_bash('command').with(cwd: '/home')

Assert that a bash was run using a regex

expect(chef_run).to run_bash('command').with(cwd: /\/(.+)/)

Assert that a bash was not run

expect(chef_run).to_not run_bash('command')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


37
38
39
# File 'lib/chefspec/api/script.rb', line 37

def run_bash(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:bash, :run, resource_name)
end

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

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

csh 'command' do
  action :run
end

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

Examples:

Assert that a csh was run

expect(chef_run).to run_csh('command')

Assert that a csh was run with predicate matchers

expect(chef_run).to run_csh('command').with_cwd('/home')

Assert that a csh was run with attributes

expect(chef_run).to run_csh('command').with(cwd: '/home')

Assert that a csh was run using a regex

expect(chef_run).to run_csh('command').with(cwd: /\/(.+)/)

Assert that a csh was not run

expect(chef_run).to_not run_csh('command')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


76
77
78
# File 'lib/chefspec/api/script.rb', line 76

def run_csh(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:csh, :run, resource_name)
end

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

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

perl 'command' do
  action :run
end

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

Examples:

Assert that a perl was run

expect(chef_run).to run_perl('command')

Assert that a perl was run with predicate matchers

expect(chef_run).to run_perl('command').with_cwd('/home')

Assert that a perl was run with attributes

expect(chef_run).to run_perl('command').with(cwd: '/home')

Assert that a perl was run using a regex

expect(chef_run).to run_perl('command').with(cwd: /\/(.+)/)

Assert that a perl was not run

expect(chef_run).to_not run_perl('command')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


115
116
117
# File 'lib/chefspec/api/script.rb', line 115

def run_perl(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:perl, :run, resource_name)
end

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

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

python 'command' do
  action :run
end

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

Examples:

Assert that a python was run

expect(chef_run).to run_python('command')

Assert that a python was run with predicate matchers

expect(chef_run).to run_python('command').with_cwd('/home')

Assert that a python was run with attributes

expect(chef_run).to run_python('command').with(cwd: '/home')

Assert that a python was run using a regex

expect(chef_run).to run_python('command').with(cwd: /\/(.+)/)

Assert that a python was not run

expect(chef_run).to_not run_python('command')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


154
155
156
# File 'lib/chefspec/api/script.rb', line 154

def run_python(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:python, :run, resource_name)
end

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

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

ruby 'command' do
  action :run
end

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

Examples:

Assert that a ruby was run

expect(chef_run).to run_ruby('command')

Assert that a ruby was run with predicate matchers

expect(chef_run).to run_ruby('command').with_cwd('/home')

Assert that a ruby was run with attributes

expect(chef_run).to run_ruby('command').with(cwd: '/home')

Assert that a ruby was run using a regex

expect(chef_run).to run_ruby('command').with(cwd: /\/(.+)/)

Assert that a ruby was not run

expect(chef_run).to_not run_ruby('command')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


193
194
195
# File 'lib/chefspec/api/script.rb', line 193

def run_ruby(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:ruby, :run, resource_name)
end

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

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

script 'command' do
  action :run
end

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

Examples:

Assert that a script was run

expect(chef_run).to run_script('command')

Assert that a script was run with predicate matchers

expect(chef_run).to run_script('command').with_cwd('/home')

Assert that a script was run with attributes

expect(chef_run).to run_script('command').with(cwd: '/home')

Assert that a script was run using a regex

expect(chef_run).to run_script('command').with(cwd: /\/(.+)/)

Assert that a script was not run

expect(chef_run).to_not run_script('command')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


232
233
234
# File 'lib/chefspec/api/script.rb', line 232

def run_script(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:script, :run, resource_name)
end