Module: ChefSpec::API::CronMatchers

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

Overview

Since:

  • 0.7.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a cron resource exists in the Chef run with the action :create. Given a Chef Recipe that creates “ping nagios” as a cron:

cron 'ping nagios' do
  action :create
end

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

Examples:

Assert that a cron was created

expect(chef_run).to create_cron('ping nagios')

Assert that a cron was created with predicate matchers

expect(chef_run).to create_cron('ping nagios').with_home('/home')

Assert that a cron was created with attributes

expect(chef_run).to create_cron('ping nagios').with(home: '/home')

Assert that a cron was created using a regex

expect(chef_run).to create_cron('ping nagios').with(home: /\/home/)

Assert that a cron was not created

expect(chef_run).to_not create_cron('ping nagios')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.7.0


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

def create_cron(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:cron, :create, resource_name)
end

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

Assert that a cron resource exists in the Chef run with the action :delete. Given a Chef Recipe that deletes “ping nagios” as a cron:

cron 'ping nagios' do
  action :delete
end

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

Examples:

Assert that a cron was deleted

expect(chef_run).to delete_cron('ping nagios')

Assert that a cron was deleted with predicate matchers

expect(chef_run).to delete_cron('ping nagios').with_home('/home')

Assert that a cron was deleted with attributes

expect(chef_run).to delete_cron('ping nagios').with(home: '/home')

Assert that a cron was deleted using a regex

expect(chef_run).to delete_cron('ping nagios').with(home: /\/home/)

Assert that a cron was not deleted

expect(chef_run).to_not delete_cron('ping nagios')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.7.0


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

def delete_cron(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:cron, :delete, resource_name)
end