Module: ChefSpec::Extensions::Chef::Resource

Defined in:
lib/chefspec/extensions/chef/resource.rb

Overview

Three concerns:

- no-op'ing so that the action does not run the provider
- tracking the actions that were performed
- auto registering helper methods

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object

auto-registration


70
71
72
73
74
# File 'lib/chefspec/extensions/chef/resource.rb', line 70

def self.prepended(base)
  class << base
    prepend ClassMethods
  end
end

Instance Method Details

#initialize(*args) ⇒ Object

tracking


40
41
42
43
# File 'lib/chefspec/extensions/chef/resource.rb', line 40

def initialize(*args)
  @performed_actions = {}
  super
end

#perform_action(action, options = {}) ⇒ Object


45
46
47
48
# File 'lib/chefspec/extensions/chef/resource.rb', line 45

def perform_action(action, options = {})
  @performed_actions[action.to_sym] ||= {}
  @performed_actions[action.to_sym].merge!(options)
end

#performed_action(action) ⇒ Object


50
51
52
# File 'lib/chefspec/extensions/chef/resource.rb', line 50

def performed_action(action)
  @performed_actions[action.to_sym]
end

#performed_action?(action) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
57
58
59
60
# File 'lib/chefspec/extensions/chef/resource.rb', line 54

def performed_action?(action)
  if action == :nothing
    performed_actions.empty?
  else
    !!performed_action(action)
  end
end

#performed_actionsObject


62
63
64
# File 'lib/chefspec/extensions/chef/resource.rb', line 62

def performed_actions
  @performed_actions.keys
end

#run_action(action, notification_type = nil, notifying_resource = nil) ⇒ Object

mix of no-op and tracking concerns


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chefspec/extensions/chef/resource.rb', line 14

def run_action(action, notification_type = nil, notifying_resource = nil)
  resolve_notification_references
  validate_action(action)

  Chef::Log.info("Processing #{self} action #{action} (#{defined_at})")

  ChefSpec::Coverage.add(self)

  unless should_skip?(action)
    if node.runner.step_into?(self)
      instance_eval { @not_if = []; @only_if = [] }
      super
    end

    if node.runner.compiling?
      perform_action(action, compile_time: true)
    else
      perform_action(action, converge_time: true)
    end
  end
end