module ChefSpec::Extensions::Chef::Resource
def self.prepended(base)
def self.prepended(base) class << base prepend ClassMethods end end
def dup
def dup return super unless $CHEFSPEC_MODE # Also here be dragons. super.tap do |dup_resource| # We're directly inside a load_current_resource, which is probably via # the load_current_value DSL system, so call this a current resource. ChefSpec::API::StubsFor.setup_stubs_for(dup_resource, :current_value) if caller.any? { |x| x.include?("`load_current_resource'") || x.include?("`load_after_resource'") } end end
def initialize(*args, &block)
Hooks for the stubs_for system
def initialize(*args, &block) super(*args, &block) if $CHEFSPEC_MODE # Here be dragons. # If we're directly inside a `load_current_resource`, this is probably # something like `new_resource.class.new` so we want to call this a current_resource, # Otherwise it's probably a normal resource instantiation. mode = :resource mode = :current_value if caller.any? { |x| x.include?("`load_current_resource'") || x.include?("`load_after_resource'") } ChefSpec::API::StubsFor.setup_stubs_for(self, mode) end end
def perform_action(action, options = {})
def perform_action(action, options = {}) @performed_actions ||= {} @performed_actions[action.to_sym] ||= {} @performed_actions[action.to_sym].merge!(options) end
def performed_action(action)
def performed_action(action) @performed_actions ||= {} @performed_actions[action.to_sym] end
def performed_action?(action)
def performed_action?(action) if action == :nothing performed_actions.empty? else !!performed_action(action) end end
def performed_actions
def performed_actions @performed_actions ||= {} @performed_actions.keys end
def run_action(action, notification_type = nil, notifying_resource = nil)
def run_action(action, notification_type = nil, notifying_resource = nil) return super unless $CHEFSPEC_MODE 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
def shell_out(*args)
def shell_out(*args) return super unless $CHEFSPEC_MODE raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "resource", resource: self) end
def shell_out_compacted(*args)
def shell_out_compacted(*args) return super unless $CHEFSPEC_MODE raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "resource", resource: self) end
def shell_out_compacted!(*args)
def shell_out_compacted!(*args) return super unless $CHEFSPEC_MODE shell_out_compacted(*args).tap(&:error!) end