Class: Halite::SpecHelper::Runner

Inherits:
ChefSpec::SoloRunner
  • Object
show all
Defined in:
lib/halite/spec_helper/runner.rb

Overview

ChefSpec runner class with Halite customizations. This adds attribute options, Halite synthetic cookbook injection, and block-based recipes.

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.

Since:

  • 1.0.0



45
46
47
48
49
50
51
52
53
54
# File 'lib/halite/spec_helper/runner.rb', line 45

def initialize(options={})
  super(options) do |node|
    # Allow inserting arbitrary attribute data in to the node
    node.attributes.default = Chef::Mixin::DeepMerge.merge(node.attributes.default, options[:default_attributes]) if options[:default_attributes]
    node.attributes.normal = Chef::Mixin::DeepMerge.merge(node.attributes.normal, options[:normal_attributes]) if options[:normal_attributes]
    node.attributes.override = Chef::Mixin::DeepMerge.merge(node.attributes.override, options[:override_attributes]) if options[:override_attributes]
    # Store the gemspec for later use
    @halite_gemspec = options[:halite_gemspec]
  end
end

Class Method Details

.converge(*recipe_names, &block) ⇒ Object

Since:

  • 1.0.0



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/halite/spec_helper/runner.rb', line 33

def self.converge(*recipe_names, &block)
  options = if recipe_names.last.is_a?(Hash)
    # Was called with options
    recipe_names.pop
  else
    {}
  end
  new(options).tap do |instance|
    instance.converge(*recipe_names, &block)
  end
end

Instance Method Details

#converge(*recipe_names, &block) ⇒ Object

Raises:

Since:

  • 1.0.0



56
57
58
59
60
61
62
63
64
65
# File 'lib/halite/spec_helper/runner.rb', line 56

def converge(*recipe_names, &block)
  raise Halite::Error.new('Cannot pass both recipe names and a recipe block to converge') if !recipe_names.empty? && block
  super(*recipe_names) do
    add_halite_cookbooks(node, @halite_gemspec) if @halite_gemspec
    if block
      recipe = Chef::Recipe.new(nil, nil, run_context)
      recipe.instance_exec(&block)
    end
  end
end