Module: ChefSpec::API::LogMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a log resource exists in the Chef run with the action :write. Given a Chef Recipe that writes “message” as a log:

log 'message' do
  action :write
end

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

Examples:

Assert that a log was writeed

expect(chef_run).to write_log('message')

Assert that a log was writeed with predicate matchers

expect(chef_run).to write_log('message').with_level(:info)

Assert that a log was writeed with attributes

expect(chef_run).to write_log('message').with(level: :info)

Assert that a log was writeed using a regex

expect(chef_run).to write_log('message').with(level: Symbol)

Assert that a log was not writeed

expect(chef_run).to_not write_log('message')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



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

def write_log(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:log, :write, resource_name)
end