rspec-puppet 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,12 @@
1
1
  require 'puppet'
2
- if Puppet.version.to_f >= 4.0
3
- require 'puppet/pops'
4
- end
5
2
  require 'fileutils'
6
3
 
4
+ begin
5
+ require 'win32/dir'
6
+ rescue LoadError
7
+ nil
8
+ end
9
+
7
10
  module RSpec::Puppet
8
11
  class Setup
9
12
  def self.run(module_name=nil)
@@ -12,6 +15,14 @@ module RSpec::Puppet
12
15
  return false
13
16
  end
14
17
 
18
+ if control_repo?
19
+ $stderr.puts <<-END
20
+ Unable to find a metadata.json file. If this is a module, please create a
21
+ metadata.json file and try again.
22
+ END
23
+ return false
24
+ end
25
+
15
26
  safe_setup_directories(module_name)
16
27
  safe_touch(File.join('spec', 'fixtures', 'manifests', 'site.pp'))
17
28
 
@@ -20,10 +31,15 @@ module RSpec::Puppet
20
31
  end
21
32
 
22
33
  def self.safe_setup_directories(module_name=nil, verbose=true)
34
+ if control_repo?
35
+ $stderr.puts "Unable to setup rspec-puppet automatically in a control repo" if verbose
36
+ return false
37
+ end
38
+
23
39
  if module_name.nil?
24
40
  module_name = get_module_name
25
41
  if module_name.nil?
26
- $stderr.puts "Unable to determine module name. Aborting"
42
+ $stderr.puts "Unable to determine module name. Aborting" if verbose
27
43
  return false
28
44
  end
29
45
  end
@@ -58,6 +74,10 @@ module RSpec::Puppet
58
74
  end
59
75
  end
60
76
  protected
77
+ def self.control_repo?
78
+ !File.exist?('metadata.json')
79
+ end
80
+
61
81
  def self.get_module_name
62
82
  module_name = nil
63
83
  Dir["manifests/*.pp"].entries.each do |manifest|
@@ -70,7 +90,8 @@ module RSpec::Puppet
70
90
  def self.get_module_name_from_file(file)
71
91
  # FIXME: see discussion at
72
92
  # https://github.com/rodjek/rspec-puppet/issues/290
73
- if Puppet.version.to_f >= 4.0
93
+ if Puppet.version.to_f >= 4.0 || RSpec.configuration.parser == 'future'
94
+ require 'puppet/pops'
74
95
  p = Puppet::Pops::Parser::Lexer2.new
75
96
  else
76
97
  p = Puppet::Parser::Lexer.new
@@ -92,18 +113,22 @@ module RSpec::Puppet
92
113
  end
93
114
 
94
115
  def self.safe_mkdir(dir, verbose=true)
95
- if File.exists? dir
116
+ if File.exist? dir
96
117
  unless File.directory? dir
97
118
  $stderr.puts "!! #{dir} already exists and is not a directory"
98
119
  end
99
120
  else
100
- FileUtils.mkdir dir
121
+ begin
122
+ FileUtils.mkdir dir
123
+ rescue Errno::EEXIST => e
124
+ raise e unless File.directory? dir
125
+ end
101
126
  puts " + #{dir}/" if verbose
102
127
  end
103
128
  end
104
129
 
105
130
  def self.safe_touch(file)
106
- if File.exists? file
131
+ if File.exist? file
107
132
  unless File.file? file
108
133
  $stderr.puts "!! #{file} already exists and is not a regular file"
109
134
  end
@@ -114,7 +139,7 @@ module RSpec::Puppet
114
139
  end
115
140
 
116
141
  def self.safe_create_file(filename, content)
117
- if File.exists? filename
142
+ if File.exist? filename
118
143
  old_content = File.read(filename)
119
144
  if old_content != content
120
145
  $stderr.puts "!! #{filename} already exists and differs from template"
@@ -132,23 +157,40 @@ module RSpec::Puppet
132
157
  safe_create_file('spec/spec_helper.rb', content)
133
158
  end
134
159
 
160
+ def self.link_to_source?(target, source)
161
+ return false unless link?(target)
162
+
163
+ link_target = Dir.respond_to?(:read_junction) ? Dir.read_junction(target) : File.readlink(target)
164
+
165
+ link_target == File.expand_path(source)
166
+ end
167
+
168
+ def self.link?(target)
169
+ Dir.respond_to?(:junction?) ? Dir.junction?(target) : File.symlink?(target)
170
+ end
171
+
135
172
  def self.safe_make_link(source, target, verbose=true)
136
- if File.exists?(target)
137
- unless File.symlink?(target) && File.readlink(target) == File.expand_path(source)
138
- $stderr.puts "!! #{target} already exists and is not a symlink"
173
+ if File.exist?(target) && !link?(target)
174
+ $stderr.puts "!! #{target} already exists and is not a symlink"
175
+ return
176
+ end
177
+
178
+ return if link_to_source?(target, source)
179
+
180
+ if Puppet::Util::Platform.windows?
181
+ output = `call mklink /J "#{target.gsub('/', '\\')}" "#{source}"`
182
+ unless $?.success?
183
+ puts output
184
+ abort
139
185
  end
140
186
  else
141
- if Puppet::Util::Platform.windows?
142
- output = `call mklink /J "#{target.gsub('/', '\\')}" "#{source}"`
143
- unless $?.success?
144
- puts output
145
- abort
146
- end
147
- else
187
+ begin
148
188
  FileUtils.ln_s(File.expand_path(source), target)
189
+ rescue Errno::EEXIST => e
190
+ raise e unless link_to_source?(target, source)
149
191
  end
150
- puts " + #{target}" if verbose
151
192
  end
193
+ puts " + #{target}" if verbose
152
194
  end
153
195
 
154
196
  def self.safe_create_rakefile
@@ -4,7 +4,6 @@ require 'rspec-puppet/raw_string'
4
4
 
5
5
  module RSpec::Puppet
6
6
  module Support
7
-
8
7
  @@cache = RSpec::Puppet::Cache.new
9
8
 
10
9
  def subject
@@ -55,28 +54,29 @@ module RSpec::Puppet
55
54
 
56
55
  munged_facts = facts_hash(nodename(type))
57
56
 
58
- if munged_facts['operatingsystem'] && munged_facts['operatingsystem'].to_s.downcase == 'windows'
59
- stub_const_wrapper('File::PATH_SEPARATOR', ';')
60
- stub_const_wrapper('File::ALT_SEPARATOR', "\\")
61
- stub_const_wrapper('Pathname::SEPARATOR_PAT', /[#{Regexp.quote(File::ALT_SEPARATOR)}#{Regexp.quote(File::SEPARATOR)}]/)
62
- else
63
- stub_const_wrapper('File::PATH_SEPARATOR', ':')
64
- stub_const_wrapper('File::ALT_SEPARATOR', nil)
65
- stub_const_wrapper('Pathname::SEPARATOR_PAT', /#{Regexp.quote(File::SEPARATOR)}/)
66
- end
57
+ pretend_platform = find_pretend_platform(munged_facts)
58
+ RSpec::Puppet::Consts.stub_consts_for(pretend_platform) unless pretend_platform.nil?
67
59
  end
68
60
 
69
- def stub_const_wrapper(const, value)
70
- if defined?(RSpec::Core::MockingAdapters::RSpec) && RSpec.configuration.mock_framework == RSpec::Core::MockingAdapters::RSpec
71
- stub_const(const, value)
72
- else
73
- klass_name, const_name = const.split('::', 2)
74
- klass = Object.const_get(klass_name)
75
- klass.send(:remove_const, const_name) if klass.const_defined?(const_name)
76
- klass.const_set(const_name, value)
61
+ def find_pretend_platform(test_facts)
62
+ from_value = lambda { |value|
63
+ value.to_s.downcase == 'windows' ? :windows : :posix
64
+ }
65
+
66
+ ['operatingsystem', 'osfamily'].each do |os_fact|
67
+ return from_value.call(test_facts[os_fact]) if test_facts.key?(os_fact)
68
+ end
69
+
70
+ if test_facts.key?('os') && test_facts['os'].is_a?(Hash)
71
+ ['name', 'family'].each do |os_hash_key|
72
+ return from_value.call(test_facts['os'][os_hash_key]) if test_facts['os'].key?(os_hash_key)
73
+ end
77
74
  end
75
+
76
+ nil
78
77
  end
79
78
 
79
+
80
80
  def load_catalogue(type, exported = false, manifest_opts = {})
81
81
  with_vardir do
82
82
  node_name = nodename(type)
@@ -84,8 +84,10 @@ module RSpec::Puppet
84
84
  hiera_config_value = self.respond_to?(:hiera_config) ? hiera_config : nil
85
85
  hiera_data_value = self.respond_to?(:hiera_data) ? hiera_data : nil
86
86
 
87
- catalogue = build_catalog(node_name, facts_hash(node_name), trusted_facts_hash(node_name), hiera_config_value,
88
- build_code(type, manifest_opts), exported, node_params_hash, hiera_data_value)
87
+ build_facts = facts_hash(node_name)
88
+ catalogue = build_catalog(node_name, build_facts, trusted_facts_hash(node_name), hiera_config_value,
89
+ build_code(type, manifest_opts), exported, node_params_hash, hiera_data_value,
90
+ RSpec.configuration.trusted_server_facts)
89
91
 
90
92
  test_module = type == :host ? nil : class_name.split('::').first
91
93
  if type == :define
@@ -95,6 +97,9 @@ module RSpec::Puppet
95
97
  end
96
98
  RSpec::Puppet::Coverage.add_from_catalog(catalogue, test_module)
97
99
 
100
+ pretend_platform = find_pretend_platform(build_facts)
101
+ Puppet::Util::Platform.pretend_to_be(pretend_platform) unless pretend_platform.nil?
102
+
98
103
  catalogue
99
104
  end
100
105
  end
@@ -144,15 +149,20 @@ module RSpec::Puppet
144
149
  end
145
150
  elsif type == :application
146
151
  if opts.has_key?(:params)
147
- "site { #{class_name} { '#{title}': #{param_str(opts[:params])} } }"
152
+ "site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"
148
153
  else
149
154
  raise ArgumentError, "You need to provide params for an application"
150
155
  end
151
156
  elsif type == :define
157
+ title_str = if title.is_a?(Array)
158
+ '[' + title.map { |r| sanitise_resource_title(r) }.join(', ') + ']'
159
+ else
160
+ sanitise_resource_title(title)
161
+ end
152
162
  if opts.has_key?(:params)
153
- "#{class_name} { #{title.inspect}: #{param_str(opts[:params])} }"
163
+ "#{class_name} { #{title_str}: #{param_str(opts[:params])} }"
154
164
  else
155
- "#{class_name} { #{title.inspect}: }"
165
+ "#{class_name} { #{title_str}: }"
156
166
  end
157
167
  elsif type == :host
158
168
  nil
@@ -161,6 +171,10 @@ module RSpec::Puppet
161
171
  end
162
172
  end
163
173
 
174
+ def sanitise_resource_title(title)
175
+ title.include?("'") ? title.inspect : "'#{title}'"
176
+ end
177
+
164
178
  def nodename(type)
165
179
  return node if self.respond_to?(:node)
166
180
  if [:class, :define, :function, :application].include? type
@@ -201,7 +215,7 @@ module RSpec::Puppet
201
215
  def facts_hash(node)
202
216
  base_facts = {
203
217
  'clientversion' => Puppet::PUPPETVERSION,
204
- 'environment' => environment,
218
+ 'environment' => environment.to_s,
205
219
  }
206
220
 
207
221
  node_facts = {
@@ -209,11 +223,12 @@ module RSpec::Puppet
209
223
  'fqdn' => node,
210
224
  'domain' => node.split('.', 2).last,
211
225
  'clientcert' => node,
212
- 'networking' => {
213
- 'fqdn' => node,
214
- 'domain' => node.split('.', 2).last,
215
- 'hostname' => node.split('.').first
216
- }
226
+ }
227
+
228
+ networking_facts = {
229
+ 'hostname' => node_facts['hostname'],
230
+ 'fqdn' => node_facts['fqdn'],
231
+ 'domain' => node_facts['domain'],
217
232
  }
218
233
 
219
234
  result_facts = if RSpec.configuration.default_facts.any?
@@ -222,9 +237,21 @@ module RSpec::Puppet
222
237
  {}
223
238
  end
224
239
 
240
+ # Merge in node facts so they always exist by default, but only if they
241
+ # haven't been defined in `RSpec.configuration.default_facts`
242
+ result_facts.merge!(munge_facts(node_facts)) { |_key, old_val, new_val| old_val.nil? ? new_val : old_val }
243
+ (result_facts['networking'] ||= {}).merge!(networking_facts) { |_key, old_val, new_val| old_val.nil? ? new_val : old_val }
244
+
245
+ # Merge in `let(:facts)` facts
225
246
  result_facts.merge!(munge_facts(base_facts))
226
247
  result_facts.merge!(munge_facts(facts)) if self.respond_to?(:facts)
227
- result_facts.merge!(munge_facts(node_facts))
248
+
249
+ # Merge node facts again on top of `let(:facts)` facts, but only if
250
+ # a node name is given with `let(:node)`
251
+ if respond_to?(:node) && RSpec.configuration.derive_node_facts_from_nodename
252
+ result_facts.merge!(munge_facts(node_facts))
253
+ (result_facts['networking'] ||= {}).merge!(networking_facts)
254
+ end
228
255
 
229
256
  # Facter currently supports lower case facts. Bug FACT-777 has been submitted to support case sensitive
230
257
  # facts.
@@ -251,13 +278,41 @@ module RSpec::Puppet
251
278
  extensions = {}
252
279
 
253
280
  if RSpec.configuration.default_trusted_facts.any?
254
- extensions.merge!(RSpec.configuration.default_trusted_facts)
281
+ extensions.merge!(munge_facts(RSpec.configuration.default_trusted_facts))
255
282
  end
256
283
 
257
- extensions.merge!(trusted_facts) if self.respond_to?(:trusted_facts)
284
+ extensions.merge!(munge_facts(trusted_facts)) if self.respond_to?(:trusted_facts)
258
285
  extensions
259
286
  end
260
287
 
288
+ def server_facts_hash
289
+ server_facts = {}
290
+
291
+ # Add our server version to the fact list
292
+ server_facts["serverversion"] = Puppet.version.to_s
293
+
294
+ # And then add the server name and IP
295
+ {"servername" => "fqdn",
296
+ "serverip" => "ipaddress"
297
+ }.each do |var, fact|
298
+ if value = Facter.value(fact)
299
+ server_facts[var] = value
300
+ else
301
+ warn "Could not retrieve fact #{fact}"
302
+ end
303
+ end
304
+
305
+ if server_facts["servername"].nil?
306
+ host = Facter.value(:hostname)
307
+ if domain = Facter.value(:domain)
308
+ server_facts["servername"] = [host, domain].join(".")
309
+ else
310
+ server_facts["servername"] = host
311
+ end
312
+ end
313
+ server_facts
314
+ end
315
+
261
316
  def str_from_value(value)
262
317
  case value
263
318
  when Hash
@@ -331,6 +386,8 @@ module RSpec::Puppet
331
386
 
332
387
  stub_facts! facts_val
333
388
 
389
+ Puppet::Type.eachtype { |type| type.defaultprovider = nil }
390
+
334
391
  node_facts = Puppet::Node::Facts.new(nodename, facts_val.dup)
335
392
  node_params = facts_val.merge(node_params)
336
393
 
@@ -343,19 +400,17 @@ module RSpec::Puppet
343
400
  },
344
401
  "Context for spec trusted hash"
345
402
  )
403
+
404
+ node_obj.add_server_facts(server_facts_hash) if RSpec.configuration.trusted_server_facts
346
405
  end
347
406
 
348
407
  adapter.catalog(node_obj, exported)
349
408
  end
350
409
 
351
410
  def stub_facts!(facts)
352
- if facts['operatingsystem'] && facts['operatingsystem'].to_s.downcase == 'windows'
353
- Puppet::Util::Platform.pretend_to_be :windows
354
- else
355
- Puppet::Util::Platform.pretend_to_be :posix
356
- end
357
- Puppet.settings[:autosign] = false
358
- facts.each { |k, v| Facter.add(k) { setcode { v } } }
411
+ Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign
412
+ Facter.clear
413
+ facts.each { |k, v| Facter.add(k, :weight => 999) { setcode { v } } }
359
414
  end
360
415
 
361
416
  def build_catalog(*args)
@@ -0,0 +1,145 @@
1
+ require 'rake'
2
+ require 'open3'
3
+ require 'json'
4
+ require 'parser/current'
5
+
6
+ task :release_test do
7
+ modules_to_test = [
8
+ 'puppetlabs/puppetlabs-apt',
9
+ 'puppetlabs/puppetlabs-tomcat',
10
+ 'puppetlabs/puppetlabs-apache',
11
+ 'puppetlabs/puppetlabs-mysql',
12
+ 'puppetlabs/puppetlabs-ntp',
13
+ 'puppetlabs/puppetlabs-acl',
14
+ 'puppetlabs/puppetlabs-chocolatey',
15
+ 'voxpupuli/puppet-archive',
16
+ 'voxpupuli/puppet-collectd',
17
+ 'garethr/garethr-docker',
18
+ 'sensu/sensu-puppet',
19
+ 'jenkinsci/puppet-jenkins',
20
+ 'rnelson0/puppet-local_user',
21
+ ]
22
+
23
+ Bundler.with_clean_env do
24
+ FileUtils.mkdir_p('tmp')
25
+ Dir.chdir('tmp') do
26
+ modules_to_test.each do |module_name|
27
+ puts "Testing #{module_name}..."
28
+ module_dir = File.basename(module_name)
29
+
30
+ if File.directory?(module_dir)
31
+ Dir.chdir(module_dir) do
32
+ print ' Updating repository... '
33
+ _, status = Open3.capture2e('git', 'pull', '--rebase')
34
+ if status.success?
35
+ puts 'Done'
36
+ else
37
+ puts 'FAILED'
38
+ next
39
+ end
40
+ end
41
+ else
42
+ print ' Cloning repository... '
43
+ _, status = Open3.capture2e('git', 'clone', "https://github.com/#{module_name}")
44
+ if status.success?
45
+ puts 'Done'
46
+ else
47
+ puts 'FAILED'
48
+ next
49
+ end
50
+ end
51
+
52
+ Dir.chdir(module_dir) do
53
+ print ' Installing dependencies... '
54
+ bundle_install_output, status = Open3.capture2e('bundle', 'install', '--path', '../vendor/gems')
55
+ if status.success?
56
+ puts 'Done'
57
+ else
58
+ puts 'FAILED'
59
+ puts bundle_install_output
60
+ next
61
+ end
62
+
63
+ print ' Running baseline tests... '
64
+ baseline_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
65
+ if status.success?
66
+ puts 'Done'
67
+ else
68
+ puts 'Done (tests failed)'
69
+ end
70
+
71
+ print ' Updating Gemfile to use rspec-puppet HEAD... '
72
+ buffer = Parser::Source::Buffer.new('Gemfile')
73
+ buffer.source = File.read('Gemfile')
74
+ parser = Parser::CurrentRuby.new
75
+ ast = parser.parse(buffer)
76
+
77
+ modified_gemfile = GemfileRewrite.new.rewrite(buffer, ast)
78
+
79
+ gem_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
80
+ if modified_gemfile == buffer.source
81
+ File.open('Gemfile', 'a') do |f|
82
+ f.puts "gem 'rspec-puppet', :path => '#{gem_root}'"
83
+ end
84
+ else
85
+ File.open('Gemfile', 'w') do |f|
86
+ f.puts modified_gemfile
87
+ end
88
+ end
89
+
90
+ puts 'Done'
91
+
92
+ print ' Installing dependencies... '
93
+ _, status = Open3.capture2e('bundle', 'install', '--path', '../vendor/gems')
94
+ if status.success?
95
+ puts 'Done'
96
+ else
97
+ puts "FAILED"
98
+ next
99
+ end
100
+
101
+ print ' Running tests against rspec-puppet HEAD... '
102
+ head_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
103
+ if status.success?
104
+ puts 'Done'
105
+ else
106
+ puts 'Done (tests failed)'
107
+ end
108
+
109
+ print ' Restoring Gemfile... '
110
+ _, status = Open3.capture2e('git', 'checkout', '--', 'Gemfile')
111
+ if status.success?
112
+ puts 'Done'
113
+ else
114
+ puts 'FAILED'
115
+ end
116
+
117
+ json_regex = %r{\{(?:[^{}]|(?:\g<0>))*\}}x
118
+ baseline_results = JSON.parse(baseline_output.scan(json_regex).find { |r| r.include?('summary_line') })
119
+ head_results = JSON.parse(head_output.scan(json_regex).find { |r| r.include?('summary_line') })
120
+ if head_results['summary_line'] == baseline_results['summary_line']
121
+ puts " PASS: #{head_results['summary_line']}"
122
+ else
123
+ puts "!!FAILED: baseline:(#{baseline_results['summary_line']}) head:(#{head_results['summary_line']})"
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ class GemfileRewrite < Parser::TreeRewriter
132
+ def on_send(node)
133
+ _, method_name, *args = *node
134
+
135
+ if method_name == :gem
136
+ gem_name = args.first
137
+ if gem_name.type == :str && gem_name.children.first == 'rspec-puppet'
138
+ gem_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
139
+ replace(node.location.expression, "gem 'rspec-puppet', :path => '#{gem_root}'")
140
+ end
141
+ end
142
+
143
+ super
144
+ end
145
+ end
data/lib/rspec-puppet.rb CHANGED
@@ -8,6 +8,7 @@ require 'rspec-puppet/example'
8
8
  require 'rspec-puppet/setup'
9
9
  require 'rspec-puppet/coverage'
10
10
  require 'rspec-puppet/adapters'
11
+ require 'rspec-puppet/consts'
11
12
 
12
13
  begin
13
14
  require 'puppet/test/test_helper'
@@ -18,29 +19,57 @@ RSpec.configure do |c|
18
19
  c.add_setting :enable_pathname_stubbing, :default => false
19
20
  end
20
21
 
22
+ module RSpec::Puppet
23
+ def self.rspec_puppet_example?
24
+ RSpec::Puppet::EventListener.rspec_puppet_example?
25
+ end
26
+
27
+ def self.current_example
28
+ RSpec::Puppet::EventListener.current_example
29
+ end
30
+ end
31
+
21
32
  require 'rspec-puppet/monkey_patches'
22
33
 
23
34
  RSpec.configure do |c|
24
- c.add_setting :environmentpath, :default => '/etc/puppetlabs/code/environments'
35
+ c.add_setting :environmentpath, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
25
36
  c.add_setting :module_path, :default => nil
26
37
  c.add_setting :manifest_dir, :default => nil
27
38
  c.add_setting :manifest, :default => nil
28
39
  c.add_setting :template_dir, :default => nil
29
40
  c.add_setting :config, :default => nil
30
- c.add_setting :confdir, :default => '/etc/puppet'
41
+ c.add_setting :confdir, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
31
42
  c.add_setting :default_facts, :default => {}
32
43
  c.add_setting :default_node_params, :default => {}
33
44
  c.add_setting :default_trusted_facts, :default => {}
34
- c.add_setting :hiera_config, :default => '/dev/null'
45
+ c.add_setting :hiera_config, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
35
46
  c.add_setting :parser, :default => 'current'
36
47
  c.add_setting :trusted_node_data, :default => false
37
48
  c.add_setting :ordering, :default => 'title-hash'
38
49
  c.add_setting :stringify_facts, :default => true
39
50
  c.add_setting :strict_variables, :default => false
51
+ c.add_setting :setup_fixtures, :default => true
52
+ c.add_setting :derive_node_facts_from_nodename, :default => true
40
53
  c.add_setting :adapter
54
+ c.add_setting :platform, :default => Puppet::Util::Platform.actual_platform
55
+ c.add_setting :vendormoduledir, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
56
+ c.add_setting :basemodulepath, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
57
+
58
+ c.instance_eval do
59
+ def trusted_server_facts
60
+ @trusted_server_facts.nil? ? false : @trusted_server_facts
61
+ end
62
+
63
+ def trusted_server_facts=(value)
64
+ @trusted_server_facts = value
65
+ adapter.setup_puppet(RSpec::Puppet.current_example) unless adapter.nil?
66
+ end
67
+ end
41
68
 
42
69
  c.before(:all) do
43
- RSpec::Puppet::Setup.safe_setup_directories(nil, false)
70
+ if RSpec.configuration.setup_fixtures?
71
+ RSpec::Puppet::Setup.safe_setup_directories(nil, false)
72
+ end
44
73
  end
45
74
 
46
75
  if defined?(Puppet::Test::TestHelper)
@@ -82,7 +111,7 @@ RSpec.configure do |c|
82
111
  end
83
112
 
84
113
  c.before :each do
85
- if self.class.ancestors.include? RSpec::Puppet::Support
114
+ if RSpec::Puppet.rspec_puppet_example?
86
115
  @adapter = RSpec::Puppet::Adapters.get
87
116
  @adapter.setup_puppet(self)
88
117
  c.adapter = adapter
@@ -90,6 +119,21 @@ RSpec.configure do |c|
90
119
  end
91
120
 
92
121
  c.before :each do |example|
93
- stub_file_consts(example) if self.respond_to?(:stub_file_consts)
122
+ if RSpec::Puppet.rspec_puppet_example?
123
+ Puppet::Util::Platform.pretend_to_be RSpec.configuration.platform
124
+ stub_file_consts(example) if self.respond_to?(:stub_file_consts)
125
+
126
+ if defined?(Selinux)
127
+ if respond_to?(:allow)
128
+ allow(Selinux).to receive(:is_selinux_enabled).and_return(0)
129
+ elsif Selinux.respond_to?(:stubs)
130
+ Selinux.stubs(:is_selinux_enabled).returns(0)
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ c.after(:each) do
137
+ RSpec::Puppet::Consts.restore_consts if RSpec::Puppet.rspec_puppet_example?
94
138
  end
95
139
  end