Module: Poise::Helpers::ChefspecMatchers

Includes:
LWRPPolyfill::Resource, ResourceName
Included in:
Resource
Defined in:
lib/poise/helpers/chefspec_matchers.rb

Overview

A resource mixin to register ChefSpec matchers for a resource automatically.

If you are using the provides() form for naming resources, ensure that is set before declaring actions.

Examples:

Define a class

class Chef::Resource::MyResource < Chef::Resource
  include Poise::Helpers::ChefspecMatchers
  actions(:run)
end

Use a matcher

expect(chef_run).to run_my_resource('...')

Since:

  • 2.0.0

Class Method Summary collapse

Methods included from ResourceName

#initialize, resource_name

Methods included from LWRPPolyfill::Resource

attribute, default_action, #initialize

Class Method Details

.actions(*names) ⇒ Object

Create matchers for all declared actions.

See Also:

  • Resource::LWRPPolyfill.actions

Since:

  • 2.0.0



75
76
77
78
79
80
81
# File 'lib/poise/helpers/chefspec_matchers.rb', line 75

def actions(*names)
  super.tap do |actions|
    actions.each do |action|
      ChefspecMatchers.create_matcher(resource_name, action)
    end
  end
end

.provides(name) ⇒ Object

Create a resource-level matcher for this resource.

See Also:

  • Resource::ResourceName.provides

Since:

  • 2.0.0



67
68
69
70
# File 'lib/poise/helpers/chefspec_matchers.rb', line 67

def provides(name)
  ChefSpec.define_matcher(name) if defined?(ChefSpec)
  super
end