module ChefSpec::API::Core::ClassMethods
Methods that will end up as group-level.
@api private
Public Instance Methods
Set automatic-level node attributes to use for this example group.
@example
describe 'myapp::install' do automatic_attributes['kernel']['machine'] = 'ppc64'
@return [Chef::Node::VividMash]
# File lib/chefspec/api/core.rb, line 175 def automatic_attributes @chefspec_automatic_attributes ||= Chef::Node::VividMash.new end
Set additional ChefSpec
runner options to use for this example group.
@example
describe 'myapp::install' do chefspec_options[:log_level] = :debug
@return [Chef::Node::VividMash]
# File lib/chefspec/api/core.rb, line 185 def chefspec_options @chefspec_options ||= Chef::Node::VividMash.new end
Set default-level node attributes to use for this example group.
@example
describe 'myapp::install' do default_attributes['myapp']['version'] = '1.0'
@return [Chef::Node::VividMash]
# File lib/chefspec/api/core.rb, line 145 def default_attributes @chefspec_default_attributes ||= Chef::Node::VividMash.new end
@api private
# 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
Set normal-level node attributes to use for this example group.
@example
describe 'myapp::install' do normal_attributes['myapp']['version'] = '1.0'
@return [Chef::Node::VividMash]
# File lib/chefspec/api/core.rb, line 155 def normal_attributes @chefspec_normal_attributes ||= Chef::Node::VividMash.new end
Set override-level node attributes to use for this example group.
@example
describe 'myapp::install' do override_attributes['myapp']['version'] = '1.0'
@return [Chef::Node::VividMash]
# File lib/chefspec/api/core.rb, line 165 def override_attributes @chefspec_override_attributes ||= Chef::Node::VividMash.new end
Set the Fauxhai platform to use for this example group.
@example
describe 'myrecipe' do platform 'ubuntu', '18.04'
@param name [String] Platform name to set. @param version [String, nil] Platform version to set. @return [void]
# File lib/chefspec/api/core.rb, line 118 def platform(name, version = nil) let(:chefspec_platform) { name } let(:chefspec_platform_version) { version } end
Use an in-line block of recipe code for this example group rather than a recipe from a cookbook.
@example
describe 'my_resource' do recipe do my_resource 'helloworld' end
@param block [Proc] A block of Chef
recipe code. @return [void]
# File lib/chefspec/api/core.rb, line 133 def recipe(&block) let(:chef_run) do chef_runner.converge_block(&block) end end
Add resources to the step_into
list for this example group.
@example
describe 'myapp::install' do step_into :my_resource
@return [Array]
# File lib/chefspec/api/core.rb, line 195 def step_into(*resources) @chefspec_step_into ||= [] @chefspec_step_into |= resources.flatten.map(&:to_s) end