Class: Cheffish::RSpec::RecipeRunWrapper
- Defined in:
- lib/cheffish/rspec/recipe_run_wrapper.rb
Instance Attribute Summary collapse
-
#example ⇒ Object
readonly
Returns the value of attribute example.
-
#recipe ⇒ Object
readonly
Returns the value of attribute recipe.
Attributes inherited from ChefRun
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(chef_config, example: nil, &recipe) ⇒ RecipeRunWrapper
constructor
A new instance of RecipeRunWrapper.
Methods inherited from ChefRun
#compile_recipe, #converge, #converge_failed?, #converged?, #event_sink, #logged_errors, #logged_info, #logged_warnings, #logs, #output_for_failure_message, #reset, #resources, #stderr, #stdout, #up_to_date?, #updated?
Constructor Details
#initialize(chef_config, example: nil, &recipe) ⇒ RecipeRunWrapper
Returns a new instance of RecipeRunWrapper.
6 7 8 9 10 |
# File 'lib/cheffish/rspec/recipe_run_wrapper.rb', line 6 def initialize(chef_config, example: nil, &recipe) super(chef_config) @recipe = recipe @example = example || recipe.binding.eval('self') end |
Instance Attribute Details
#example ⇒ Object (readonly)
Returns the value of attribute example.
13 14 15 |
# File 'lib/cheffish/rspec/recipe_run_wrapper.rb', line 13 def example @example end |
#recipe ⇒ Object (readonly)
Returns the value of attribute recipe.
12 13 14 |
# File 'lib/cheffish/rspec/recipe_run_wrapper.rb', line 12 def recipe @recipe end |
Instance Method Details
#client ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cheffish/rspec/recipe_run_wrapper.rb', line 15 def client if !@client super example = self.example # Call into the rspec example's let variables and other methods @client.define_singleton_method(:method_missing) do |name, *args, &block| # the elimination of a bunch of metaprogramming in 12.4 changed how Chef DSL is defined in code, # requiring a slight contortion for earlier versions. if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('12.4') # incompatibility introduced at 2b364df if example.respond_to?(name) example.public_send(name, *args, &block) end else begin super(name, *args, &block) rescue NameError if example.respond_to?(name) example.public_send(name, *args, &block) else raise end end end end # This is called by respond_to?, and is required to make sure the # resource knows that we will in fact call the given method. @client.define_singleton_method(:respond_to_missing?) do |name, include_private = false| example.respond_to?(name) || super(name, include_private) end # Respond true to is_a?(Chef::Provider) so that Chef::Recipe::DSL.build_resource # will hook resources up to the example let variables as well (via # enclosing_provider). # Please don't hurt me @client.define_singleton_method(:is_a?) do |klass| klass == Chef::Provider || super(klass) end @client.load_block(&recipe) end @client end |