Module: ChefSpec::API::Core::ClassMethods Private

Included in:
ChefSpec::API::Core
Defined in:
lib/chefspec/api/core.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Methods that will end up as group-level.

API:

  • private

Instance Method Summary collapse

Instance Method Details

#automatic_attributesChef::Node::VividMash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set automatic-level node attributes to use for this example group.

Examples:

describe 'myapp::install' do
  automatic_attributes['kernel']['machine'] = 'ppc64'

Returns:

API:

  • private



175
176
177
# File 'lib/chefspec/api/core.rb', line 175

def automatic_attributes
  @chefspec_automatic_attributes ||= Chef::Node::VividMash.new
end

#chefspec_optionsChef::Node::VividMash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set additional ChefSpec runner options to use for this example group.

Examples:

describe 'myapp::install' do
  chefspec_options[:log_level] = :debug

Returns:

API:

  • private



185
186
187
# File 'lib/chefspec/api/core.rb', line 185

def chefspec_options
  @chefspec_options ||= Chef::Node::VividMash.new
end

#default_attributesChef::Node::VividMash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set default-level node attributes to use for this example group.

Examples:

describe 'myapp::install' do
  default_attributes['myapp']['version'] = '1.0'

Returns:

API:

  • private



145
146
147
# File 'lib/chefspec/api/core.rb', line 145

def default_attributes
  @chefspec_default_attributes ||= Chef::Node::VividMash.new
end

#included(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



201
202
203
204
205
206
207
208
209
210
# File 'lib/chefspec/api/core.rb', line 201

def included(klass)
  super
  # Inject classmethods into the group.
  klass.extend(ClassMethods)
  # If the describe block is aimed at string or resource/provider class
  # then set the default subject to be the Chef run.
  if klass.described_class.nil? || klass.described_class.is_a?(Class) && (klass.described_class < Chef::Resource || klass.described_class < Chef::Provider)
    klass.subject { chef_run }
  end
end

#normal_attributesChef::Node::VividMash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set normal-level node attributes to use for this example group.

Examples:

describe 'myapp::install' do
  normal_attributes['myapp']['version'] = '1.0'

Returns:

API:

  • private



155
156
157
# File 'lib/chefspec/api/core.rb', line 155

def normal_attributes
  @chefspec_normal_attributes ||= Chef::Node::VividMash.new
end

#override_attributesChef::Node::VividMash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set override-level node attributes to use for this example group.

Examples:

describe 'myapp::install' do
  override_attributes['myapp']['version'] = '1.0'

Returns:

API:

  • private



165
166
167
# File 'lib/chefspec/api/core.rb', line 165

def override_attributes
  @chefspec_override_attributes ||= Chef::Node::VividMash.new
end

#platform(name, version = nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Set the Fauxhai platform to use for this example group.

Examples:

describe 'myrecipe' do
  platform 'ubuntu', '18.04'

Parameters:

  • Platform name to set.

  • (defaults to: nil)

    Platform version to set.

API:

  • private



118
119
120
121
# File 'lib/chefspec/api/core.rb', line 118

def platform(name, version = nil)
  let(:chefspec_platform) { name }
  let(:chefspec_platform_version) { version }
end

#recipe(&block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Use an in-line block of recipe code for this example group rather than a recipe from a cookbook.

Examples:

describe 'my_resource' do
  recipe do
    my_resource 'helloworld'
  end

Parameters:

  • A block of Chef recipe code.

API:

  • private



133
134
135
136
137
# File 'lib/chefspec/api/core.rb', line 133

def recipe(&block)
  let(:chef_run) do
    chef_runner.converge_block(&block)
  end
end

#step_into(*resources) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add resources to the step_into list for this example group.

Examples:

describe 'myapp::install' do
  step_into :my_resource

Returns:

API:

  • private



195
196
197
198
# File 'lib/chefspec/api/core.rb', line 195

def step_into(*resources)
  @chefspec_step_into ||= []
  @chefspec_step_into |= resources.flatten.map(&:to_s)
end