Module: ChefSpec::API::NotificationsMatchers

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

Overview

Since:

  • 0.9.0

Instance Method Summary collapse

Instance Method Details

#new_notifyObject



130
# File 'lib/chefspec/deprecations.rb', line 130

alias_method :new_notify, :notify

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

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

ifconfig '10.0.0.1' do
  action :add
end

The Examples section demonstrates the different ways to test an ifconfig 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
37
38
39
40
41
42
43
# File 'lib/chefspec/api/notifications.rb', line 34

def notify(resource, action = nil)
  if action
    deprecated "The `notify` matcher arity has changed. Please use" \
      " `notify(#{resource.inspect}).to(#{action.to_sym.inspect})`" \
      " instead."
      new_notify(resource).to(action.to_sym)
  else
    new_notify(resource)
  end
end