class RSpec::Puppet::Adapters::Adapter40

Public Instance Methods

catalog(node, exported) click to toggle source
Calls superclass method RSpec::Puppet::Adapters::Base#catalog
# File lib/rspec-puppet/adapters.rb, line 158
def catalog(node, exported)
  node.environment = current_environment
  # Override $::environment to workaround PUP-5835, where Puppet otherwise
  # stores a symbol for the parameter
  node.parameters['environment'] = current_environment.name.to_s if node.parameters['environment'] != node.parameters['environment'].to_s
  super
end
current_environment() click to toggle source
# File lib/rspec-puppet/adapters.rb, line 166
def current_environment
  Puppet.lookup(:current_environment)
end
manifest() click to toggle source

Puppet 4.0 specially handles environments that don't have a manifest set, so we check for the no manifest value and return nil when it is set.

@return [String, nil] The path to the Puppet manifest if it is present and set, nil otherwise.

# File lib/rspec-puppet/adapters.rb, line 178
def manifest
  m = current_environment.manifest
  if m == Puppet::Node::Environment::NO_MANIFEST
    nil
  else
    m
  end
end
modulepath() click to toggle source
# File lib/rspec-puppet/adapters.rb, line 170
def modulepath
  current_environment.modulepath
end
settings_map() click to toggle source
# File lib/rspec-puppet/adapters.rb, line 149
def settings_map
  super.concat([
    [:environmentpath, :environmentpath],
    [:hiera_config, :hiera_config],
    [:strict_variables, :strict_variables],
    [:manifest, :manifest],
  ])
end
setup_puppet(example_group) click to toggle source
# File lib/rspec-puppet/adapters.rb, line 111
def setup_puppet(example_group)
  super

  if rspec_modulepath = RSpec.configuration.module_path
    modulepath = rspec_modulepath.split(File::PATH_SEPARATOR)
  else
    modulepath = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
      File.join(path, 'fixtures', 'modules')
    end
  end

  if rspec_manifest = RSpec.configuration.manifest
    manifest = rspec_manifest
  else
    manifest_paths = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
      File.join(path, 'fixtures', 'manifests')
    end

    manifest = manifest_paths.find do |path|
      File.exist?(path)
    end

    manifest ||= Puppet::Node::Environment::NO_MANIFEST
  end

  env = Puppet::Node::Environment.create(@environment_name, modulepath, manifest)
  loader = Puppet::Environments::Static.new(env)

  Puppet.push_context(
    {
      :environments => loader,
      :current_environment => env,
      :loaders => (Puppet::Pops::Loaders.new(env) if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0')),
    },
    "Setup rspec-puppet environments"
  )
end