Module: ChefSpec::API::ServiceMatchers

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

Overview

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

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

Assert that a service resource exists in the Chef run with the action :disable. Given a Chef Recipe that disables “apache2” as a service:

service 'apache2' do
  action :disable
end

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

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

Examples:

Assert that a service was disabled

expect(chef_run).to disable_service('apache2')

Assert that a service was disabled with predicate matchers

expect(chef_run).to disable_service('apache2').with_pattern('apa*')

Assert that a service was disabled with attributes

expect(chef_run).to disable_service('apache2').with(pattern: 'apa*')

Assert that a service was disabled using a regex

expect(chef_run).to disable_service('apache2').with(patthen: /(.+)/)

Assert that a service was not disabled

expect(chef_run).to_not disable_service('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


42
43
44
# File 'lib/chefspec/api/service.rb', line 42

def disable_service(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:service, :disable, resource_name)
end

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

Assert that a service resource exists in the Chef run with the action :enable. Given a Chef Recipe that enables “apache2” as a service:

service 'apache2' do
  action :enable
end

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

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

Examples:

Assert that a service was enabled

expect(chef_run).to enable_service('apache2')

Assert that a service was enabled with predicate matchers

expect(chef_run).to enable_service('apache2').with_pattern('apa*')

Assert that a service was enabled with attributes

expect(chef_run).to enable_service('apache2').with(pattern: 'apa*')

Assert that a service was enabled using a regex

expect(chef_run).to enable_service('apache2').with(patthen: /(.+)/)

Assert that a service was not enabled

expect(chef_run).to_not enable_service('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


82
83
84
# File 'lib/chefspec/api/service.rb', line 82

def enable_service(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:service, :enable, resource_name)
end

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

Assert that a service resource exists in the Chef run with the action :reload. Given a Chef Recipe that reloads “apache2” as a service:

service 'apache2' do
  action :reload
end

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

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

Examples:

Assert that a service was reload

expect(chef_run).to reload_service('apache2')

Assert that a service was reload with predicate matchers

expect(chef_run).to reload_service('apache2').with_pattern('apa*')

Assert that a service was reload with attributes

expect(chef_run).to reload_service('apache2').with(pattern: 'apa*')

Assert that a service was reload using a regex

expect(chef_run).to reload_service('apache2').with(patthen: /(.+)/)

Assert that a service was not reload

expect(chef_run).to_not reload_service('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


122
123
124
# File 'lib/chefspec/api/service.rb', line 122

def reload_service(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:service, :reload, resource_name)
end

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

Assert that a service resource exists in the Chef run with the action :restart. Given a Chef Recipe that restarts “apache2” as a service:

service 'apache2' do
  action :restart
end

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

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

Examples:

Assert that a service was restarted

expect(chef_run).to restart_service('apache2')

Assert that a service was restarted with predicate matchers

expect(chef_run).to restart_service('apache2').with_pattern('apa*')

Assert that a service was restarted with attributes

expect(chef_run).to restart_service('apache2').with(pattern: 'apa*')

Assert that a service was restarted using a regex

expect(chef_run).to restart_service('apache2').with(patthen: /(.+)/)

Assert that a service was not restarted

expect(chef_run).to_not restart_service('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


162
163
164
# File 'lib/chefspec/api/service.rb', line 162

def restart_service(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:service, :restart, resource_name)
end

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

Assert that a service resource exists in the Chef run with the action :start. Given a Chef Recipe that starts “apache2” as a service:

service 'apache2' do
  action :start
end

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

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

Examples:

Assert that a service was started

expect(chef_run).to start_service('apache2')

Assert that a service was started with predicate matchers

expect(chef_run).to start_service('apache2').with_pattern('apa*')

Assert that a service was started with attributes

expect(chef_run).to start_service('apache2').with(pattern: 'apa*')

Assert that a service was started using a regex

expect(chef_run).to start_service('apache2').with(patthen: /(.+)/)

Assert that a service was not started

expect(chef_run).to_not start_service('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


202
203
204
# File 'lib/chefspec/api/service.rb', line 202

def start_service(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:service, :start, resource_name)
end

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

Assert that a service resource exists in the Chef run with the action :stop. Given a Chef Recipe that stops “apache2” as a service:

service 'apache2' do
  action :stop
end

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

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

Examples:

Assert that a service was stopped

expect(chef_run).to stop_service('apache2')

Assert that a service was stopped with predicate matchers

expect(chef_run).to stop_service('apache2').with_pattern('apa*')

Assert that a service was stopped with attributes

expect(chef_run).to stop_service('apache2').with(pattern: 'apa*')

Assert that a service was stopped using a regex

expect(chef_run).to stop_service('apache2').with(patthen: /(.+)/)

Assert that a service was not stopped

expect(chef_run).to_not stop_service('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


242
243
244
# File 'lib/chefspec/api/service.rb', line 242

def stop_service(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:service, :stop, resource_name)
end