|
51 | 51 | # Continue gracefully |
52 | 52 | end |
53 | 53 |
|
54 | | -# This is just a utility class to allow us to isolate the various version-specific |
55 | | -# branches of initialization logic into methods without polluting the global namespace.# |
56 | | -class Puppet::PuppetSpecInitializer |
57 | | - # This method is for initializing puppet state for testing for older versions |
58 | | - # of puppet that do not support the new TestHelper API. As you can see, |
59 | | - # this involves explicitly modifying global variables, directly manipulating |
60 | | - # Puppet's Settings singleton object, and other fun implementation details |
61 | | - # that code external to puppet should really never know about. |
62 | | - def self.initialize_via_fallback_compatibility(config) |
63 | | - warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.') |
64 | | - config.before :all do |
65 | | - # nothing to do for now |
66 | | - end |
67 | | - |
68 | | - config.after :all do |
69 | | - # nothing to do for now |
70 | | - end |
71 | | - |
72 | | - config.before :each do |
73 | | - # these globals are set by Application |
74 | | - $puppet_application_mode = nil # rubocop:disable Style/GlobalVars |
75 | | - $puppet_application_name = nil # rubocop:disable Style/GlobalVars |
76 | | - |
77 | | - # REVISIT: I think this conceals other bad tests, but I don't have time to |
78 | | - # fully diagnose those right now. When you read this, please come tell me |
79 | | - # I suck for letting this float. --daniel 2011-04-21 |
80 | | - Signal.stubs(:trap) |
81 | | - |
82 | | - # Set the confdir and vardir to gibberish so that tests |
83 | | - # have to be correctly mocked. |
84 | | - Puppet[:confdir] = '/dev/null' |
85 | | - Puppet[:vardir] = '/dev/null' |
86 | | - |
87 | | - # Avoid opening ports to the outside world |
88 | | - Puppet.settings[:bindaddress] = '127.0.0.1' |
89 | | - end |
90 | | - |
91 | | - config.after :each do |
92 | | - Puppet.settings.clear |
93 | | - |
94 | | - Puppet::Node::Environment.clear |
95 | | - Puppet::Util::Storage.clear |
96 | | - Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub' |
97 | | - |
98 | | - PuppetlabsSpec::Files.cleanup |
99 | | - end |
100 | | - end |
101 | | -end |
102 | | - |
103 | | -# JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534) |
104 | | -unless Puppet.constants.include? 'Test' |
105 | | - module Puppet::Test |
106 | | - # This is a stub class to allow the stdlib tests to run in Puppet 2.6 |
107 | | - # This class will be removed in another commit. |
108 | | - class LogCollector |
109 | | - def initialize(logs) |
110 | | - @logs = logs |
111 | | - end |
112 | | - |
113 | | - def <<(value) |
114 | | - @logs << value |
115 | | - end |
116 | | - end |
117 | | - end |
118 | | - Puppet::Util::Log.newdesttype :log_collector do |
119 | | - match 'Puppet::Test::LogCollector' |
120 | | - |
121 | | - def initialize(messages) |
122 | | - @messages = messages |
123 | | - end |
124 | | - |
125 | | - def handle(msg) |
126 | | - @messages << msg |
127 | | - end |
128 | | - end |
129 | | -end |
130 | | - |
131 | 54 | # And here is where we do the main rspec configuration / setup. |
132 | 55 | RSpec.configure do |config| |
133 | 56 | # Detect whether the module is overriding the choice of mocking framework |
134 | 57 | # @mock_framework is used since more than seven years, and we need to avoid |
135 | 58 | # `mock_framework`'s autoloading to distinguish between the default, and |
136 | 59 | # the module's choice. |
137 | 60 | if config.instance_variable_get(:@mock_framework).nil? |
138 | | - RSpec.warn_deprecation('puppetlabs_spec_helper: defaults `mock_with` to `:mocha`. See https://github.com/puppetlabs/puppetlabs_spec_helper#mock_with to choose a sensible value for you') |
139 | | - config.mock_with :mocha |
140 | | - end |
141 | | - |
142 | | - # determine whether we can use the new API or not, and call the appropriate initializer method. |
143 | | - if defined?(Puppet::Test::TestHelper) |
144 | | - # This case is handled by rspec-puppet since v1.0.0 (via 41257b33cb1f9ade4426b044f70be511b0c89112) |
145 | | - else |
146 | | - Puppet::PuppetSpecInitializer.initialize_via_fallback_compatibility(config) |
| 61 | + config.mock_with :rspec |
147 | 62 | end |
148 | 63 |
|
149 | 64 | # Here we do some general setup that is relevant to all initialization modes, regardless |
|
0 commit comments