Module: ChefSpec::API::Core
- Extended by:
- ClassMethods, RSpec::SharedContext
- Defined in:
- lib/chefspec/api/core.rb
Overview
Module containing the core RSpec API for ChefSpec.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#chef_runner_class ⇒ Class
abstract
Class of runner to use.
-
#chef_runner_instance ⇒ ChefSpec::SoloRunner
Create an instance of the runner.
-
#chef_runner_options ⇒ Hash<Symbol, Object>
abstract
Compute the options for the runner.
-
#chefspec_ancestor_gather(start, method, &block) ⇒ Object
private
Helper method for some of the nestable test value methods like ClassMethods#default_attributes and ClassMethods#step_into.
-
#chefspec_attributes(method) ⇒ Mash
private
Special case of #chefspec_ancestor_gather because we do it four times.
Methods included from ClassMethods
automatic_attributes, chefspec_options, default_attributes, included, normal_attributes, override_attributes, platform, recipe, step_into
Instance Method Details
#chef_runner_class ⇒ Class
Class of runner to use.
59 60 61 |
# File 'lib/chefspec/api/core.rb', line 59 def chef_runner_class ChefSpec::SoloRunner end |
#chef_runner_instance ⇒ ChefSpec::SoloRunner
Create an instance of the runner.
This should only be used in cases where the ‘let()` cache would be a problem.
68 69 70 |
# File 'lib/chefspec/api/core.rb', line 68 def chef_runner_instance chef_runner_class.new() end |
#chef_runner_options ⇒ Hash<Symbol, Object>
Compute the options for the runner.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/chefspec/api/core.rb', line 37 def = { step_into: chefspec_ancestor_gather([], :step_into) { |memo, val| memo | val }, default_attributes: chefspec_default_attributes, normal_attributes: chefspec_normal_attributes, override_attributes: chefspec_override_attributes, automatic_attributes: chefspec_automatic_attributes, spec_declaration_locations: self.class.declaration_locations.last[0], } # Only specify these if set in the example so we don't override the # global settings. [:platform] = chefspec_platform if chefspec_platform [:version] = chefspec_platform_version if chefspec_platform_version # Merge in any final overrides. .update(chefspec_attributes(:chefspec_options).symbolize_keys) end |
#chefspec_ancestor_gather(start, method, &block) ⇒ 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.
Helper method for some of the nestable test value methods like ChefSpec::API::Core::ClassMethods#default_attributes and ChefSpec::API::Core::ClassMethods#step_into.
87 88 89 90 91 92 |
# File 'lib/chefspec/api/core.rb', line 87 def chefspec_ancestor_gather(start, method, &block) candidate_ancestors = self.class.ancestors.select { |cls| cls.respond_to?(method) && cls != ChefSpec::API::Core } candidate_ancestors.reverse.inject(start) do |memo, cls| block.call(memo, cls.send(method)) end end |
#chefspec_attributes(method) ⇒ Mash
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.
Special case of #chefspec_ancestor_gather because we do it four times.
100 101 102 103 104 |
# File 'lib/chefspec/api/core.rb', line 100 def chefspec_attributes(method) chefspec_ancestor_gather(Mash.new, method) do |memo, val| Chef::Mixin::DeepMerge.merge(memo, val) end end |