Module: ChefSpec::API::Subscriptions

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

Instance Method Summary collapse

Instance Method Details

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

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

service 'apache2' do
  subscribes :create, 'template[/etc/apache2/config]'
end

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

Examples:

Assert a basic subscription

service = chef_run.service('apache2')
expect(service).to subscribe_to('template[/etc/apache2/config]')

Assert a subscription with specified action

expect(service).to subscribe_to('template[/etc/apache2/config]').on(:restart)

Assert a subscription with specified action and timing

expect(service).to subscribe_to('template[/etc/apache2/config]').on(:restart).immediately

Parameters:

  • signature (String)

    the signature of the notification to match

Returns:



31
32
33
# File 'lib/chefspec/api/subscriptions.rb', line 31

def subscribe_to(signature)
  ChefSpec::Matchers::SubscribesMatcher.new(signature)
end