module Halite::SpecHelper

A helper module for RSpec tests of resource-based cookbooks.

@since 1.0.0 @example

describe MyMixin do
  resource(:my_thing) do
    include Poise
    include MyMixin
    action(:install)
    attribute(:path, kind_of: String, default: '/etc/thing')
  end
  provider(:my_thing) do
    include Poise
    def action_install
      file new_resource.path do
        content new_resource.my_mixin
      end
    end
  end
  recipe do
    my_thing 'test'
  end

  it { is_expected.to create_file('/etc/thing').with(content: 'mixin stuff') }
end

Public Class Methods

described_class() click to toggle source
# File lib/halite/spec_helper.rb, line 58
def self.described_class; nil; end

Public Instance Methods

chef_runner_class() click to toggle source

Custom runner class.

# File lib/halite/spec_helper.rb, line 118
def chef_runner_class
  Halite::SpecHelper::Runner
end
chef_runner_options() click to toggle source

Merge in extra options data.

Calls superclass method
# File lib/halite/spec_helper.rb, line 106
def chef_runner_options
  super.tap do |options|
    options[:halite_gemspec] = halite_gemspec
    # And some legacy data.
    options[:default_attributes].update(default_attributes)
    options[:normal_attributes].update(normal_attributes)
    options[:override_attributes].update(override_attributes)
    options.update(chefspec_options)
  end
end
provider(name) click to toggle source

Return a helper-defined provider.

@param name [Symbol] Name of the provider. @return [Class] @example

subject { provider(:my_provider) }
# File lib/halite/spec_helper.rb, line 156
def provider(name)
  self.class.providers[name.to_sym]
end
resource(name) click to toggle source

Return a helper-defined resource.

@param name [Symbol] Name of the resource. @return [Class] @example

subject { resource(:my_resource) }
# File lib/halite/spec_helper.rb, line 146
def resource(name)
  self.class.resources[name.to_sym]
end
run_chef() click to toggle source

An alias for slightly more semantic meaning, just forces the lazy subject to run.

@see www.relishapp.com/rspec/rspec-core/v/3-2/docs/subject/explicit-subject RSpec's subject helper @example

describe 'my recipe' do
  recipe 'my_recipe'
  it { run_chef }
end
# File lib/halite/spec_helper.rb, line 136
def run_chef
  chef_run
end