class Halite::SpecHelper::Runner
ChefSpec runner class with Halite
customizations. This adds attribute options, Halite
synthetic cookbook injection, and block-based recipes.
@since 1.0.0
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
# File lib/halite/spec_helper/runner.rb, line 33 def initialize(options={}) # Store the gemspec for later use @halite_gemspec = options[:halite_gemspec] super end
Public Instance Methods
converge(*args, &block)
click to toggle source
Calls superclass method
# File lib/halite/spec_helper/runner.rb, line 42 def converge(*args, &block) super(*args) do |node| add_halite_cookbooks(node, @halite_gemspec) if @halite_gemspec block.call(node) if block end end
preload!()
click to toggle source
# File lib/halite/spec_helper/runner.rb, line 39 def preload! end
Private Instance Methods
add_halite_cookbooks(node, gemspecs)
click to toggle source
# File lib/halite/spec_helper/runner.rb, line 51 def add_halite_cookbooks(node, gemspecs) Array(gemspecs).each do |gemspec| gem_data = Halite::Gem.new(gemspec) # Catch any dependency loops. next if run_context.cookbook_collection.include?(gem_data.cookbook_name) && run_context.cookbook_collection[gem_data.cookbook_name].respond_to?(:halite_root) run_context.cookbook_collection[gem_data.cookbook_name] = gem_data.as_cookbook_version gem_data.cookbook_dependencies.each do |dep| add_halite_cookbooks(node, dep.spec) if dep.spec end # Add to the compiler for RunContext#unreachable_cookbook? cookbook_order = run_context.instance_variable_get(:@cookbook_compiler).cookbook_order name_sym = gem_data.cookbook_name.to_sym cookbook_order << name_sym unless cookbook_order.include?(name_sym) # Load attributes if any. gem_data.each_file('chef/attributes') do |_full_path, rel_path| raise Halite::Error.new("Chef does not support nested attribute files: #{rel_path}") if rel_path.include?(File::SEPARATOR) name = File.basename(rel_path, '.rb') node.include_attribute("#{gem_data.cookbook_name}::#{name}") end end end
apply_chef_config!()
click to toggle source
Inject a better chefspec_cookbook_root option.
Calls superclass method
# File lib/halite/spec_helper/runner.rb, line 91 def apply_chef_config! super if @halite_gemspec Chef::Config[:chefspec_cookbook_root] = Array(@halite_gemspec).first.full_gem_path end end
calling_cookbook_path(*args)
click to toggle source
Don't try to autodetect the calling cookbook.
# File lib/halite/spec_helper/runner.rb, line 86 def calling_cookbook_path(*args) File.expand_path('../empty', __FILE__) end
cookbook()
click to toggle source
Override the normal cookbook loading behavior.
Calls superclass method
# File lib/halite/spec_helper/runner.rb, line 74 def cookbook if @halite_gemspec halite_gem = Halite::Gem.new(Array(@halite_gemspec).first) Chef::Cookbook::Metadata.new.tap do |metadata| metadata.name(halite_gem.cookbook_name) end else super end end