Class: RSpec::Puppet::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-puppet/adapters.rb

Direct Known Subclasses

Adapter27, Adapter3X, Adapter4X

Instance Method Summary collapse

Instance Method Details

#catalog(node, exported) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/rspec-puppet/adapters.rb', line 69

def catalog(node, exported)
  if exported
    # Use the compiler directly to skip the filtering done by the indirector
    Puppet::Parser::Compiler.compile(node).filter { |r| !r.exported? }
  else
    Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node)
  end
end

#current_environmentObject



78
79
80
# File 'lib/rspec-puppet/adapters.rb', line 78

def current_environment
  Puppet::Node::Environment.new(@environment_name)
end

#manifestString?

Returns The path to the Puppet manifest if it is present and set, nil otherwise.

Returns:

  • (String, nil)

    The path to the Puppet manifest if it is present and set, nil otherwise.



95
96
97
# File 'lib/rspec-puppet/adapters.rb', line 95

def manifest
  Puppet[:manifest]
end

#modulepathObject



90
91
92
# File 'lib/rspec-puppet/adapters.rb', line 90

def modulepath
  Puppet[:modulepath].split(File::PATH_SEPARATOR)
end

#set_setting(example_group, puppet_setting, rspec_setting) ⇒ void

This method returns an undefined value.

Set up a specific Puppet setting. configuration setting.

Puppet setting values can be taken from the global RSpec configuration, or from the currently executing RSpec context. When a setting is specified both in the global configuration and in the example group, the setting in the example group is preferred.

Examples:

Configuring a Puppet setting from a global RSpec configuration value

RSpec.configure do |config|
  config.parser = "future"
end
# => Puppet[:parser] will be future

Configuring a Puppet setting from within an RSpec example group

RSpec.describe 'my_module::my_class', :type => :class do
  let(:module_path) { "/Users/luke/modules" }
  #=> Puppet[:modulepath] will be "/Users/luke/modules"
end

Configuring a Puppet setting with both a global RSpec configuration and local context

RSpec.configure do |config|
  config.confdir = "/etc/puppet"
end
RSpec.describe 'my_module', :type => :class do
  # Puppet[:confdir] will be "/etc/puppet"
end
RSpec.describe 'my_module::my_class', :type => :class do
  let(:confdir) { "/etc/puppetlabs/puppet" }
  # => Puppet[:confdir] will be "/etc/puppetlabs/puppet" in this example group
end
RSpec.describe 'my_module::my_define', :type => :define do
  # Puppet[:confdir] will be "/etc/puppet" again
end

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    The RSpec context to use for local settings

  • puppet_setting (Symbol)

    The name of the Puppet setting to configure

  • rspec_setting (Symbol)

    The name of the RSpec context specific or global setting to use



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rspec-puppet/adapters.rb', line 54

def set_setting(example_group, puppet_setting, rspec_setting)
  if example_group.respond_to?(rspec_setting)
    value = example_group.send(rspec_setting)
  else
    value = RSpec.configuration.send(rspec_setting)
  end
  begin
    Puppet[puppet_setting] = value
  rescue ArgumentError
    # TODO: this silently swallows errors when applying settings that the current
    # Puppet version does not accept, which means that user specified settings
    # are ignored. This may lead to suprising behavior for users.
  end
end

#settings_mapObject



82
83
84
85
86
87
88
# File 'lib/rspec-puppet/adapters.rb', line 82

def settings_map
  [
    [:modulepath, :module_path],
    [:config, :config],
    [:confdir, :confdir],
  ]
end

#setup_puppet(example_group) ⇒ void

This method returns an undefined value.

Set up all Puppet settings applicable for this Puppet version

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    The RSpec context to use for local settings



9
10
11
12
13
14
# File 'lib/rspec-puppet/adapters.rb', line 9

def setup_puppet(example_group)
  settings_map.each do |puppet_setting, rspec_setting|
    set_setting(example_group, puppet_setting, rspec_setting)
  end
  @environment_name = example_group.environment
end