Module: ChefSpec::API::RubyBlockMatchers

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

Overview

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a ruby_block resource exists in the Chef run with the action :run. Given a Chef Recipe that runs “do_something” as a ruby_block:

ruby_block 'do_something' do
  block do
    # ...
  end
  action :run
end

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

Examples:

Assert that a ruby_block was run

expect(chef_run).to run_ruby_block('do_something')

Assert that a ruby_block was not run

expect(chef_run).to_not run_ruby_block('do_something')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.5.0


33
34
35
# File 'lib/chefspec/api/ruby_block.rb', line 33

def run_ruby_block(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:ruby_block, :run, resource_name)
end