class Object
Public Class Methods
# File lib/chefspec/extensions/chef/provider.rb, line 9 def self.inspect "#<Module: #{name}>" end
# File lib/chefspec/extensions/chef/provider.rb, line 5 def self.name "ChefSpec extensions for Chef::Provider" end
# 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
# 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
# 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
# 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
# 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 phases that should not run during preload
# 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
# 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
@see Chef::DSL::DataQuery#data_bag
# 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
@see Chef::DSL::DataQuery#data_bag_item
# 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
@see Chef::Resource::Conditional#evaluate_command
# 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
Installs the gems into the omnibus gemset.
# 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
Compile phases that should only ever run once, globally.
# 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
# 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
# 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
# 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
# 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
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
# File lib/chefspec/extensions/ohai/system.rb, line 7 def run_additional_plugins(plugin_path) return super unless $CHEFSPEC_MODE # noop end
Don’t actually run ohai (we have fake data for that)
@see Chef::Client#run_ohai
# File lib/chefspec/extensions/chef/client.rb, line 17 def run_ohai return super unless $CHEFSPEC_MODE # noop end
@see Chef::DSL::DataQuery#search
# File lib/chefspec/extensions/chef/data_query.rb, line 5 def search(*args, &block) return super unless Chef::Config[:solo] && $CHEFSPEC_MODE type = args[0] query = args[1] || "*:*" stub = ChefSpec::Stubs::SearchRegistry.stub_for(type, query) if stub.nil? raise ChefSpec::Error::SearchNotStubbed.new(args: [type, query]) end if block Array(stub.result).each { |r| block.call(r) } true else stub.result end end
# 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
# 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
# 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
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]
# File lib/chefspec/extensions/chef/resource/freebsd_package.rb, line 12 def supports_pkgng? return super unless $CHEFSPEC_MODE true end
Don’t validate uploaded cookbooks. Validating a cookbook takes forever to complete. It’s just not worth it…
# File lib/chefspec/extensions/chef/cookbook_uploader.rb, line 8 def validate_cookbooks return super unless $CHEFSPEC_MODE # noop end