Class: Puppet::PuppetSpecInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetlabs_spec_helper/puppet_spec_helper.rb

Class Method Summary collapse

Class Method Details

.initialize_via_fallback_compatibility(config) ⇒ Object

This method is for initializing puppet state for testing for older versions of puppet that do not support the new TestHelper API. As you can see, this involves explicitly modifying global variables, directly manipulating Puppet's Settings singleton object, and other fun implementation details that code external to puppet should really never know about.


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/puppetlabs_spec_helper/puppet_spec_helper.rb', line 62

def self.initialize_via_fallback_compatibility(config)
  warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
  config.before :all do
    # nothing to do for now
  end

  config.after :all do
    # nothing to do for now
  end

  config.before :each do
    # these globals are set by Application
    $puppet_application_mode = nil
    $puppet_application_name = nil

    # REVISIT: I think this conceals other bad tests, but I don't have time to
    # fully diagnose those right now.  When you read this, please come tell me
    # I suck for letting this float. --daniel 2011-04-21
    Signal.stubs(:trap)

    # Set the confdir and vardir to gibberish so that tests
    # have to be correctly mocked.
    Puppet[:confdir] = '/dev/null'
    Puppet[:vardir] = '/dev/null'

    # Avoid opening ports to the outside world
    Puppet.settings[:bindaddress] = '127.0.0.1'
  end

  config.after :each do
    Puppet.settings.clear

    Puppet::Node::Environment.clear
    Puppet::Util::Storage.clear
    Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'

    PuppetlabsSpec::Files.cleanup
  end
end