class Object

Public Class Methods

inspect() click to toggle source
# File lib/chefspec/extensions/chef/provider.rb, line 9
def self.inspect
  "#<Module: #{name}>"
end
name() click to toggle source
# File lib/chefspec/extensions/chef/provider.rb, line 5
def self.name
  "ChefSpec extensions for Chef::Provider"
end
new(resource, run_context) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/lwrp_base.rb, line 8
def initialize(resource, run_context)
  super
  @run_context = run_context
  @resource_collection = run_context.resource_collection
end

Public Instance Methods

action(name, &block) click to toggle source
# File lib/chefspec/extensions/chef/lwrp_base.rb, line 16
def action(name, &block)
  # Note: This does not check $CHEFSPEC_MODE.
  define_method("action_#{name}", &block)
end
all_directories_in_repo_paths() click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/cookbook_loader.rb, line 4
def all_directories_in_repo_paths
  return super unless $CHEFSPEC_MODE

  if Chef::Config[:chefspec_cookbook_root]
    # Hax.
    [Chef::Config[:chefspec_cookbook_root]]
  else
    super
  end
end
compile_and_converge_action(&block) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/lwrp_base.rb, line 23
def compile_and_converge_action(&block)
  return super unless $CHEFSPEC_MODE

  instance_eval(&block)
end
compile_attributes() click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 71
def compile_attributes
  return super unless $CHEFSPEC_MODE
  return if $CHEFSPEC_PRELOAD

  super
end
compile_ohai_plugins() click to toggle source

Compile phases that should not run during preload

Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 64
def compile_ohai_plugins
  return super unless $CHEFSPEC_MODE
  return if $CHEFSPEC_PRELOAD

  super
end
compile_recipes() click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 78
def compile_recipes
  return super unless $CHEFSPEC_MODE
  return if $CHEFSPEC_PRELOAD

  super
end
data_bag(bag) click to toggle source

@see Chef::DSL::DataQuery#data_bag

Calls superclass method
# File lib/chefspec/extensions/chef/data_query.rb, line 25
def data_bag(bag)
  return super unless Chef::Config[:solo] && $CHEFSPEC_MODE

  stub = ChefSpec::Stubs::DataBagRegistry.stub_for(bag)

  if stub.nil?
    raise ChefSpec::Error::DataBagNotStubbed.new(args: [bag])
  end

  stub.result
end
data_bag_item(bag, id, secret = nil) click to toggle source

@see Chef::DSL::DataQuery#data_bag_item

Calls superclass method
# File lib/chefspec/extensions/chef/data_query.rb, line 38
def data_bag_item(bag, id, secret = nil)
  return super unless Chef::Config[:solo] && $CHEFSPEC_MODE

  stub = ChefSpec::Stubs::DataBagItemRegistry.stub_for(bag, id)

  if stub.nil?
    raise ChefSpec::Error::DataBagItemNotStubbed.new(args: [bag, id])
  end

  stub.result
end
evaluate_command() click to toggle source

@see Chef::Resource::Conditional#evaluate_command

Calls superclass method
# File lib/chefspec/extensions/chef/conditional.rb, line 5
def evaluate_command
  return super unless $CHEFSPEC_MODE

  stub = ChefSpec::Stubs::CommandRegistry.stub_for(@command)

  if stub.nil?
    raise ChefSpec::Error::CommandNotStubbed.new(args: [@command])
  end

  stub.result
end
install() click to toggle source

Installs the gems into the omnibus gemset.

Calls superclass method
# File lib/chefspec/extensions/chef/cookbook/gem_installer.rb, line 5
def install
  return super unless $CHEFSPEC_MODE

  cookbook_gems = Hash.new { |h, k| h[k] = [] }

  cookbook_collection.each do |cookbook_name, cookbook_version|
    cookbook_version.metadata.gems.each do |args|
      cookbook_gems[args.first] += args[1..-1]
    end
  end

  events.cookbook_gem_start(cookbook_gems)
  cookbook_gems.each { |gem_name, gem_requirements| locate_gem(gem_name, gem_requirements) }
  events.cookbook_gem_finished
end
load_libraries_from_cookbook(cookbook) click to toggle source

Compile phases that should only ever run once, globally.

Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 16
def load_libraries_from_cookbook(cookbook)
  return super unless $CHEFSPEC_MODE

  $CHEFSPEC_LIBRARY_PRELOAD ||= {}
  # Already loaded this once.
  return if $CHEFSPEC_LIBRARY_PRELOAD[cookbook]

  $CHEFSPEC_LIBRARY_PRELOAD[cookbook] = true
  super
end
load_lwrps_from_cookbook(cookbook) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 38
def load_lwrps_from_cookbook(cookbook)
  return super unless $CHEFSPEC_MODE

  $CHEFSPEC_LWRP_PRELOAD ||= {}
  # Already loaded this once.
  return if $CHEFSPEC_LWRP_PRELOAD[cookbook]

  $CHEFSPEC_LWRP_PRELOAD[cookbook] = true
  super
end
load_ohai_plugins_from_cookbook(cookbook) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 27
def load_ohai_plugins_from_cookbook(cookbook)
  return super unless $CHEFSPEC_MODE

  $CHEFSPEC_OHAI_PRELOAD ||= {}
  # Already loaded this once.
  return if $CHEFSPEC_OHAI_PRELOAD[cookbook]

  $CHEFSPEC_OHAI_PRELOAD[cookbook] = true
  super
end
load_resource_definitions_from_cookbook(cookbook) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb, line 49
def load_resource_definitions_from_cookbook(cookbook)
  return super unless $CHEFSPEC_MODE

  $CHEFSPEC_DEFINITION_PRELOAD ||= {}
  # Already loaded this once.
  return if $CHEFSPEC_DEFINITION_PRELOAD[cookbook]

  $CHEFSPEC_DEFINITION_PRELOAD[cookbook] = true
  super
end
locate_gem(gem_name, gem_requirements) click to toggle source
# File lib/chefspec/extensions/chef/cookbook/gem_installer.rb, line 23
def locate_gem(gem_name, gem_requirements)
  ::Gem::Specification.find_by_name(gem_name, gem_requirements)
rescue ::Gem::MissingSpecError
  gem_cmd = "gem install #{gem_name} --version '#{gem_requirements.join(", ")}'"
  gemfile_line = "gem '#{[gem_name, *gem_requirements].join("', '")}'"
  warn "No matching version found for '#{gem_name}' in your gem environment.\n" \
       " - if you are using Chef Workstation, run the following command: \"chef #{gem_cmd}\"\n" \
       " - if you are using bundler, append \"#{gemfile_line}\" to your Gemfile and run \"bundle install\"\n" \
       " - otherwise run: \"#{gem_cmd}\""
end
run_additional_plugins(plugin_path) click to toggle source

If an Ohai segment exists, don’t actually pull data in for ohai. (we have fake data for that) @see Ohai::System#run_additional_plugins

Calls superclass method
# File lib/chefspec/extensions/ohai/system.rb, line 7
def run_additional_plugins(plugin_path)
  return super unless $CHEFSPEC_MODE
  # noop
end
run_ohai() click to toggle source

Don’t actually run ohai (we have fake data for that)

@see Chef::Client#run_ohai

Calls superclass method
# File lib/chefspec/extensions/chef/client.rb, line 17
def run_ohai
  return super unless $CHEFSPEC_MODE
  # noop
end
shell_out(*args) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/provider.rb, line 33
def shell_out(*args)
  return super unless $CHEFSPEC_MODE

  raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "provider", resource: new_resource)
end
shell_out_compacted(*args) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/provider.rb, line 21
def shell_out_compacted(*args)
  return super unless $CHEFSPEC_MODE

  raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "provider", resource: new_resource)
end
shell_out_compacted!(*args) click to toggle source
Calls superclass method
# File lib/chefspec/extensions/chef/provider.rb, line 27
def shell_out_compacted!(*args)
  return super unless $CHEFSPEC_MODE

  shell_out_compacted(*args).tap(&:error!)
end
supports_pkgng?() click to toggle source

Chef decided it was a good idea to just shellout inside of a resource. Not only is that a horrible fucking idea, but I got flak when I asked to change it. So we are just going to monkey patch the fucking thing so it does not shell out.

@return [false]

Calls superclass method
# File lib/chefspec/extensions/chef/resource/freebsd_package.rb, line 12
def supports_pkgng?
  return super unless $CHEFSPEC_MODE

  true
end
validate_cookbooks() click to toggle source

Don’t validate uploaded cookbooks. Validating a cookbook takes forever to complete. It’s just not worth it…

Calls superclass method
# File lib/chefspec/extensions/chef/cookbook_uploader.rb, line 8
def validate_cookbooks
  return super unless $CHEFSPEC_MODE
  # noop
end