Module: ChefSpec::API::NotificationsMatchers

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

Overview

Since:

  • 0.9.0

Instance Method Summary collapse

Instance Method Details

#notify(signature) ⇒ ChefSpec::Matchers::NotificationsMatcher

Assert that a resource notifies another. Given a Chef Recipe that notifies a template resource to restart apache:

template '/etc/apache2/config' do
  notifies :restart, 'service[apache2]'
end

The Examples section demonstrates the different ways to test an notifications on a resource with ChefSpec.

Examples:

Assert the template notifies apache of something

template = chef_run.template('/etc/apache2.conf')
expect(template).to notify('service[apache2]')

Assert the template notifies apache to restart

expect(template).to notify('service[apache2]').to(:restart)

Assert the template notifies apache to restart immediately

expect(template).to notify('service[apache2]').to(:restart).immediately

Assert the template notifies apache to restart delayed

expect(template).to notify('service[apache2]').to(:restart).delayed

Parameters:

  • signature (String)

    the signature of the notification to match

Returns:

Since:

  • 0.9.0


34
35
36
# File 'lib/chefspec/api/notifications.rb', line 34

def notify(signature)
  ChefSpec::Matchers::NotificationsMatcher.new(signature)
end