Class: ChefSpec::ServerRunner

Inherits:
SoloRunner show all
Includes:
ServerMethods
Defined in:
lib/chefspec/server_runner.rb

Instance Attribute Summary

Attributes inherited from SoloRunner

#options, #run_context

Instance Method Summary collapse

Methods included from ServerMethods

#client, #clients, #create_client, #create_data_bag, #create_environment, #create_node, #create_role, #data, #data_bag, entity, #environment, #environments, #get, #has_client?, #has_data_bag?, #has_environment?, #has_node?, #has_role?, #load_data, #node, #nodes, #role, #roles, #server

Methods inherited from SoloRunner

#compiling?, converge, #converge_block, define_runner_method, #dry_run?, #find_resource, #find_resources, #inspect, #method_missing, #node, #preload!, #resource_collection, #respond_to_missing?, #step_into?, #to_s

Methods included from Normalize

#resource_name

Constructor Details

#initialize(options = {}) {|node, _self| ... } ⇒ ServerRunner

Returns a new instance of ServerRunner.

Yields:

Yield Parameters:

See Also:

  • ChefSpec::ServerRunner.(SoloRunner(SoloRunner#initialize)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chefspec/server_runner.rb', line 14

def initialize(options = {})
  # Unlike the SoloRunner, the file_cache_path needs to remain consistent
  # for every Chef run or else the Chef client tries to loads the same
  # cookbook multiple times and will encounter deprecated logic when
  # creating LWRPs. It also slows down the entire process.
  options[:file_cache_path] ||= RSpec.configuration.file_cache_path ||
    ChefSpec::FileCachePathProxy.instance.file_cache_path

  # Call super, but do not pass in the block because we want to customize
  # our yielding.
  super(options, &nil)

  # Unlike the SoloRunner, the node AND server object are yielded for
  # customization
  yield node, self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ChefSpec::SoloRunner

Instance Method Details

#converge(*recipe_names) ⇒ Object

See Also:

  • ChefSpec::ServerRunner.(SoloRunner(SoloRunner#converge)


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chefspec/server_runner.rb', line 32

def converge(*recipe_names)
  ChefSpec::ZeroServer.upload_cookbooks!

  super do
    yield if block_given?

    # Save the node back to the server for searching purposes
    client.register
    node.save
  end
end