rspec-puppet 2.12.0 → 3.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +139 -483
  3. data/README.md +18 -5
  4. data/bin/rspec-puppet-init +4 -3
  5. data/lib/rspec-puppet/adapters.rb +67 -61
  6. data/lib/rspec-puppet/cache.rb +3 -2
  7. data/lib/rspec-puppet/consts.rb +16 -14
  8. data/lib/rspec-puppet/coverage.rb +37 -42
  9. data/lib/rspec-puppet/errors.rb +6 -6
  10. data/lib/rspec-puppet/example/application_example_group.rb +3 -1
  11. data/lib/rspec-puppet/example/class_example_group.rb +3 -1
  12. data/lib/rspec-puppet/example/define_example_group.rb +3 -1
  13. data/lib/rspec-puppet/example/function_example_group.rb +28 -23
  14. data/lib/rspec-puppet/example/host_example_group.rb +3 -1
  15. data/lib/rspec-puppet/example/provider_example_group.rb +2 -0
  16. data/lib/rspec-puppet/example/type_alias_example_group.rb +4 -2
  17. data/lib/rspec-puppet/example/type_example_group.rb +3 -1
  18. data/lib/rspec-puppet/example.rb +6 -7
  19. data/lib/rspec-puppet/facter_impl.rb +11 -10
  20. data/lib/rspec-puppet/matchers/allow_value.rb +10 -10
  21. data/lib/rspec-puppet/matchers/compile.rb +54 -61
  22. data/lib/rspec-puppet/matchers/count_generic.rb +18 -18
  23. data/lib/rspec-puppet/matchers/create_generic.rb +66 -78
  24. data/lib/rspec-puppet/matchers/dynamic_matchers.rb +13 -2
  25. data/lib/rspec-puppet/matchers/include_class.rb +5 -4
  26. data/lib/rspec-puppet/matchers/parameter_matcher.rb +11 -12
  27. data/lib/rspec-puppet/matchers/raise_error.rb +5 -1
  28. data/lib/rspec-puppet/matchers/run.rb +41 -44
  29. data/lib/rspec-puppet/matchers/type_matchers.rb +37 -48
  30. data/lib/rspec-puppet/matchers.rb +2 -0
  31. data/lib/rspec-puppet/monkey_patches/win32/registry.rb +7 -5
  32. data/lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb +3 -1
  33. data/lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb +208 -205
  34. data/lib/rspec-puppet/monkey_patches.rb +56 -56
  35. data/lib/rspec-puppet/rake_task.rb +6 -4
  36. data/lib/rspec-puppet/raw_string.rb +2 -0
  37. data/lib/rspec-puppet/sensitive.rb +9 -7
  38. data/lib/rspec-puppet/setup.rb +43 -48
  39. data/lib/rspec-puppet/spec_helper.rb +2 -0
  40. data/lib/rspec-puppet/support.rb +133 -134
  41. data/lib/rspec-puppet/tasks/release_test.rb +8 -5
  42. data/lib/rspec-puppet/version.rb +5 -0
  43. data/lib/rspec-puppet.rb +43 -51
  44. metadata +11 -9
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec-puppet/cache'
2
4
  require 'rspec-puppet/adapters'
3
5
  require 'rspec-puppet/raw_string'
@@ -11,7 +13,7 @@ module RSpec::Puppet
11
13
  @@fixture_hiera_configs = Hash.new { |h, k| h[k] = nil }
12
14
 
13
15
  def subject
14
- lambda { catalogue }
16
+ -> { catalogue }
15
17
  end
16
18
 
17
19
  def environment
@@ -19,7 +21,7 @@ module RSpec::Puppet
19
21
  end
20
22
 
21
23
  def build_code(type, manifest_opts)
22
- if Puppet.version.to_f >= 4.0 or Puppet[:parser] == 'future'
24
+ if (Puppet.version.to_f >= 4.0) || (Puppet[:parser] == 'future')
23
25
  [site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
24
26
  else
25
27
  [import_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
@@ -28,21 +30,21 @@ module RSpec::Puppet
28
30
 
29
31
  def guess_type_from_path(path)
30
32
  case path
31
- when /spec\/defines/
33
+ when %r{spec/defines}
32
34
  :define
33
- when /spec\/classes/
35
+ when %r{spec/classes}
34
36
  :class
35
- when /spec\/functions/
37
+ when %r{spec/functions}
36
38
  :function
37
- when /spec\/hosts/
39
+ when %r{spec/hosts}
38
40
  :host
39
- when /spec\/types/
41
+ when %r{spec/types}
40
42
  :type
41
- when /spec\/type_aliases/
43
+ when %r{spec/type_aliases}
42
44
  :type_alias
43
- when /spec\/provider/
45
+ when %r{spec/provider}
44
46
  :provider
45
- when /spec\/applications/
47
+ when %r{spec/applications}
46
48
  :application
47
49
  else
48
50
  :unknown
@@ -50,11 +52,11 @@ module RSpec::Puppet
50
52
  end
51
53
 
52
54
  def stub_file_consts(example)
53
- if example.respond_to?(:metadata)
54
- type = example.metadata[:type]
55
- else
56
- type = guess_type_from_path(example.example.metadata[:file_path])
57
- end
55
+ type = if example.respond_to?(:metadata)
56
+ example.metadata[:type]
57
+ else
58
+ guess_type_from_path(example.example.metadata[:file_path])
59
+ end
58
60
 
59
61
  munged_facts = facts_hash(nodename(type))
60
62
 
@@ -64,15 +66,15 @@ module RSpec::Puppet
64
66
 
65
67
  def find_pretend_platform(test_facts)
66
68
  from_value = lambda { |value|
67
- value.to_s.downcase == 'windows' ? :windows : :posix
69
+ value.to_s.casecmp('windows').zero? ? :windows : :posix
68
70
  }
69
71
 
70
- ['operatingsystem', 'osfamily'].each do |os_fact|
72
+ %w[operatingsystem osfamily].each do |os_fact|
71
73
  return from_value.call(test_facts[os_fact]) if test_facts.key?(os_fact)
72
74
  end
73
75
 
74
76
  if test_facts.key?('os') && test_facts['os'].is_a?(Hash)
75
- ['name', 'family'].each do |os_hash_key|
77
+ %w[name family].each do |os_hash_key|
76
78
  return from_value.call(test_facts['os'][os_hash_key]) if test_facts['os'].key?(os_hash_key)
77
79
  end
78
80
  end
@@ -80,20 +82,19 @@ module RSpec::Puppet
80
82
  nil
81
83
  end
82
84
 
83
-
84
85
  def load_catalogue(type, exported = false, manifest_opts = {})
85
86
  with_vardir do
86
87
  node_name = nodename(type)
87
88
 
88
- hiera_config_value = self.respond_to?(:hiera_config) ? hiera_config : nil
89
- hiera_data_value = self.respond_to?(:hiera_data) ? hiera_data : nil
89
+ hiera_config_value = respond_to?(:hiera_config) ? hiera_config : nil
90
+ hiera_data_value = respond_to?(:hiera_data) ? hiera_data : nil
90
91
 
91
- rspec_config_values = [
92
- :trusted_server_facts,
93
- :disable_module_hiera,
94
- :use_fixture_spec_hiera,
95
- :fixture_hiera_configs,
96
- :fallback_to_default_hiera,
92
+ rspec_config_values = %i[
93
+ trusted_server_facts
94
+ disable_module_hiera
95
+ use_fixture_spec_hiera
96
+ fixture_hiera_configs
97
+ fallback_to_default_hiera
97
98
  ].map { |setting| RSpec.configuration.send(setting) }
98
99
 
99
100
  build_facts = facts_hash(node_name)
@@ -108,7 +109,7 @@ module RSpec::Puppet
108
109
  trusted_external_data: trusted_external_data_hash,
109
110
  ignored_cache_params: {
110
111
  hiera_data_value: hiera_data_value,
111
- rspec_config_values: rspec_config_values,
112
+ rspec_config_values: rspec_config_values
112
113
  }
113
114
  )
114
115
 
@@ -128,25 +129,25 @@ module RSpec::Puppet
128
129
  end
129
130
 
130
131
  def import_str
131
- import_str = ""
132
- adapter.modulepath.each { |d|
133
- if File.exists?(File.join(d, 'manifests', 'init.pp'))
132
+ import_str = ''
133
+ adapter.modulepath.each do |d|
134
+ if File.exist?(File.join(d, 'manifests', 'init.pp'))
134
135
  path_to_manifest = File.join([
135
136
  d,
136
137
  'manifests',
137
- class_name.split('::')[1..-1]
138
+ class_name.split('::')[1..]
138
139
  ].flatten)
139
140
  import_str = [
140
141
  "import '#{d}/manifests/init.pp'",
141
142
  "import '#{path_to_manifest}.pp'",
142
- '',
143
+ ''
143
144
  ].join("\n")
144
145
  break
145
- elsif File.exists?(d)
146
+ elsif File.exist?(d)
146
147
  import_str = "import '#{adapter.manifest}'\n"
147
148
  break
148
149
  end
149
- }
150
+ end
150
151
 
151
152
  import_str
152
153
  end
@@ -167,34 +168,34 @@ module RSpec::Puppet
167
168
  end
168
169
 
169
170
  def test_manifest(type, opts = {})
170
- opts[:params] = params if self.respond_to?(:params)
171
+ opts[:params] = params if respond_to?(:params)
171
172
 
172
- if type == :class
173
+ case type
174
+ when :class
173
175
  if opts[:params].nil? || opts[:params] == {}
174
176
  "include #{class_name}"
175
177
  else
176
178
  "class { '#{class_name}': #{param_str(opts[:params])} }"
177
179
  end
178
- elsif type == :application
179
- if opts.has_key?(:params)
180
- "site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"
181
- else
182
- raise ArgumentError, "You need to provide params for an application"
183
- end
184
- elsif type == :define
180
+ when :application
181
+ raise ArgumentError, 'You need to provide params for an application' unless opts.key?(:params)
182
+
183
+ "site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"
184
+
185
+ when :define
185
186
  title_str = if title.is_a?(Array)
186
187
  '[' + title.map { |r| sanitise_resource_title(r) }.join(', ') + ']'
187
188
  else
188
189
  sanitise_resource_title(title)
189
190
  end
190
- if opts.has_key?(:params)
191
+ if opts.key?(:params)
191
192
  "#{class_name} { #{title_str}: #{param_str(opts[:params])} }"
192
193
  else
193
194
  "#{class_name} { #{title_str}: }"
194
195
  end
195
- elsif type == :host
196
+ when :host
196
197
  nil
197
- elsif type == :type_alias
198
+ when :type_alias
198
199
  "$test = #{str_from_value(opts[:test_value])}\nassert_type(#{self.class.top_level_description}, $test)"
199
200
  end
200
201
  end
@@ -204,8 +205,9 @@ module RSpec::Puppet
204
205
  end
205
206
 
206
207
  def nodename(type)
207
- return node if self.respond_to?(:node)
208
- if [:class, :define, :function, :application].include? type
208
+ return node if respond_to?(:node)
209
+
210
+ if %i[class define function application].include? type
209
211
  Puppet[:certname]
210
212
  else
211
213
  class_name
@@ -217,47 +219,43 @@ module RSpec::Puppet
217
219
  end
218
220
 
219
221
  def pre_cond
220
- if self.respond_to?(:pre_condition) && !pre_condition.nil?
221
- if pre_condition.is_a? Array
222
- pre_condition.compact.join("\n")
223
- else
224
- pre_condition
225
- end
222
+ return unless respond_to?(:pre_condition) && !pre_condition.nil?
223
+
224
+ if pre_condition.is_a? Array
225
+ pre_condition.compact.join("\n")
226
226
  else
227
- nil
227
+ pre_condition
228
228
  end
229
229
  end
230
230
 
231
231
  def post_cond
232
- if self.respond_to?(:post_condition) && !post_condition.nil?
233
- if post_condition.is_a? Array
234
- post_condition.compact.join("\n")
235
- else
236
- post_condition
237
- end
232
+ return unless respond_to?(:post_condition) && !post_condition.nil?
233
+
234
+ if post_condition.is_a? Array
235
+ post_condition.compact.join("\n")
238
236
  else
239
- nil
237
+ post_condition
240
238
  end
241
239
  end
242
240
 
243
241
  def facts_hash(node)
244
242
  base_facts = {
245
243
  'clientversion' => Puppet::PUPPETVERSION,
246
- 'environment' => environment.to_s,
244
+ 'environment' => environment.to_s
247
245
  }
248
246
 
249
247
  node_facts = {
250
- 'hostname' => node.split('.').first,
251
- 'fqdn' => node,
252
- 'domain' => node.split('.', 2).last,
248
+ 'hostname' => node.split('.').first,
249
+ 'fqdn' => node,
250
+ 'domain' => node.split('.', 2).last,
253
251
  'clientcert' => node,
254
- 'ipaddress6' => 'FE80:0000:0000:0000:AAAA:AAAA:AAAA',
252
+ 'ipaddress6' => 'FE80:0000:0000:0000:AAAA:AAAA:AAAA'
255
253
  }
256
254
 
257
255
  networking_facts = {
258
256
  'hostname' => node_facts['hostname'],
259
- 'fqdn' => node_facts['fqdn'],
260
- 'domain' => node_facts['domain'],
257
+ 'fqdn' => node_facts['fqdn'],
258
+ 'domain' => node_facts['domain']
261
259
  }
262
260
 
263
261
  result_facts = if RSpec.configuration.default_facts.any?
@@ -269,11 +267,13 @@ module RSpec::Puppet
269
267
  # Merge in node facts so they always exist by default, but only if they
270
268
  # haven't been defined in `RSpec.configuration.default_facts`
271
269
  result_facts.merge!(munge_facts(node_facts)) { |_key, old_val, new_val| old_val.nil? ? new_val : old_val }
272
- (result_facts['networking'] ||= {}).merge!(networking_facts) { |_key, old_val, new_val| old_val.nil? ? new_val : old_val }
270
+ (result_facts['networking'] ||= {}).merge!(networking_facts) do |_key, old_val, new_val|
271
+ old_val.nil? ? new_val : old_val
272
+ end
273
273
 
274
274
  # Merge in `let(:facts)` facts
275
275
  result_facts.merge!(munge_facts(base_facts))
276
- result_facts.merge!(munge_facts(facts)) if self.respond_to?(:facts)
276
+ result_facts.merge!(munge_facts(facts)) if respond_to?(:facts)
277
277
 
278
278
  # Merge node facts again on top of `let(:facts)` facts, but only if
279
279
  # a node name is given with `let(:node)`
@@ -284,8 +284,7 @@ module RSpec::Puppet
284
284
 
285
285
  # Facter currently supports lower case facts. Bug FACT-777 has been submitted to support case sensitive
286
286
  # facts.
287
- downcase_facts = Hash[result_facts.map { |k, v| [k.downcase, v] }]
288
- downcase_facts
287
+ result_facts.transform_keys(&:downcase)
289
288
  end
290
289
 
291
290
  def node_params_hash
@@ -301,7 +300,7 @@ module RSpec::Puppet
301
300
  param_str_from_hash(params)
302
301
  end
303
302
 
304
- def trusted_facts_hash(node_name)
303
+ def trusted_facts_hash(_node_name)
305
304
  return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
306
305
 
307
306
  extensions = {}
@@ -310,7 +309,7 @@ module RSpec::Puppet
310
309
  extensions.merge!(munge_facts(RSpec.configuration.default_trusted_facts))
311
310
  end
312
311
 
313
- extensions.merge!(munge_facts(trusted_facts)) if self.respond_to?(:trusted_facts)
312
+ extensions.merge!(munge_facts(trusted_facts)) if respond_to?(:trusted_facts)
314
313
  extensions
315
314
  end
316
315
 
@@ -323,7 +322,7 @@ module RSpec::Puppet
323
322
  external_data.merge!(munge_facts(RSpec.configuration.default_trusted_external_data))
324
323
  end
325
324
 
326
- external_data.merge!(munge_facts(trusted_external_data)) if self.respond_to?(:trusted_external_data)
325
+ external_data.merge!(munge_facts(trusted_external_data)) if respond_to?(:trusted_external_data)
327
326
  external_data
328
327
  end
329
328
 
@@ -331,26 +330,25 @@ module RSpec::Puppet
331
330
  server_facts = {}
332
331
 
333
332
  # Add our server version to the fact list
334
- server_facts["serverversion"] = Puppet.version.to_s
333
+ server_facts['serverversion'] = Puppet.version.to_s
335
334
 
336
335
  # And then add the server name and IP
337
- {"servername" => "fqdn",
338
- "serverip" => "ipaddress"
339
- }.each do |var, fact|
340
- if value = FacterImpl.value(fact)
336
+ { 'servername' => 'fqdn',
337
+ 'serverip' => 'ipaddress' }.each do |var, fact|
338
+ if (value = FacterImpl.value(fact))
341
339
  server_facts[var] = value
342
340
  else
343
341
  warn "Could not retrieve fact #{fact}"
344
342
  end
345
343
  end
346
344
 
347
- if server_facts["servername"].nil?
345
+ if server_facts['servername'].nil?
348
346
  host = FacterImpl.value(:hostname)
349
- if domain = FacterImpl.value(:domain)
350
- server_facts["servername"] = [host, domain].join(".")
351
- else
352
- server_facts["servername"] = host
353
- end
347
+ server_facts['servername'] = if (domain = FacterImpl.value(:domain))
348
+ [host, domain].join('.')
349
+ else
350
+ host
351
+ end
354
352
  end
355
353
  server_facts
356
354
  end
@@ -358,19 +356,19 @@ module RSpec::Puppet
358
356
  def str_from_value(value)
359
357
  case value
360
358
  when Hash
361
- kvs = value.collect do |k,v|
359
+ kvs = value.collect do |k, v|
362
360
  "#{str_from_value(k)} => #{str_from_value(v)}"
363
- end.join(", ")
361
+ end.join(', ')
364
362
  "{ #{kvs} }"
365
363
  when Array
366
364
  vals = value.map do |v|
367
365
  str_from_value(v)
368
- end.join(", ")
366
+ end.join(', ')
369
367
  "[ #{vals} ]"
370
368
  when :default
371
- 'default' # verbatim default keyword
369
+ 'default' # verbatim default keyword
372
370
  when :undef
373
- 'undef' # verbatim undef keyword
371
+ 'undef' # verbatim undef keyword
374
372
  when Symbol
375
373
  str_from_value(value.to_s)
376
374
  else
@@ -381,8 +379,8 @@ module RSpec::Puppet
381
379
  def param_str_from_hash(params_hash)
382
380
  # the param_str has special quoting rules, because the top-level keys are the Puppet
383
381
  # params, which may not be quoted
384
- params_hash.collect do |k,v|
385
- "#{k.to_s} => #{str_from_value(v)}"
382
+ params_hash.collect do |k, v|
383
+ "#{k} => #{str_from_value(v)}"
386
384
  end.join(', ')
387
385
  end
388
386
 
@@ -392,7 +390,7 @@ module RSpec::Puppet
392
390
 
393
391
  # Enable app_management by default for Puppet versions that support it
394
392
  if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5
395
- Puppet[:app_management] = ENV.include?('PUPPET_NOAPP_MANAGMENT') ? false : true
393
+ Puppet[:app_management] = !ENV.include?('PUPPET_NOAPP_MANAGMENT')
396
394
  end
397
395
 
398
396
  adapter.modulepath.map do |d|
@@ -405,25 +403,24 @@ module RSpec::Puppet
405
403
  end
406
404
 
407
405
  def with_vardir
408
- begin
409
- vardir = setup_puppet
410
- return yield(vardir) if block_given?
411
- ensure
412
- FileUtils.rm_rf(vardir) if vardir && File.directory?(vardir)
413
- end
406
+ vardir = setup_puppet
407
+ return yield(vardir) if block_given?
408
+ ensure
409
+ FileUtils.rm_rf(vardir) if vardir && File.directory?(vardir)
414
410
  end
415
411
 
416
- def build_catalog_without_cache(nodename, facts_val, trusted_facts_val, hiera_config_val, code, exported, node_params, *_)
412
+ def build_catalog_without_cache(nodename, facts_val, trusted_facts_val, hiera_config_val, code, exported,
413
+ node_params, *_)
417
414
  build_catalog_without_cache_v2({
418
- nodename: nodename,
419
- facts_val: facts_val,
420
- trusted_facts_val: trusted_facts_val,
421
- hiera_config_val: hiera_config_val,
422
- code: code,
423
- exported: exported,
424
- node_params: node_params,
425
- trusted_external: {},
426
- })
415
+ nodename: nodename,
416
+ facts_val: facts_val,
417
+ trusted_facts_val: trusted_facts_val,
418
+ hiera_config_val: hiera_config_val,
419
+ code: code,
420
+ exported: exported,
421
+ node_params: node_params,
422
+ trusted_external: {}
423
+ })
427
424
  end
428
425
 
429
426
  def build_catalog_without_cache_v2(
@@ -445,7 +442,7 @@ module RSpec::Puppet
445
442
  # It would be nice if Puppet offered a public API for invalidating their
446
443
  # cached instance of Hiera, but que sera sera. We will go directly against
447
444
  # the implementation out of absolute necessity.
448
- HieraPuppet.instance_variable_set('@hiera', nil) if defined? HieraPuppet
445
+ HieraPuppet.instance_variable_set(:@hiera, nil) if defined? HieraPuppet
449
446
 
450
447
  Puppet[:code] = code
451
448
 
@@ -456,18 +453,16 @@ module RSpec::Puppet
456
453
  node_facts = Puppet::Node::Facts.new(nodename, facts_val.dup)
457
454
  node_params = facts_val.merge(node_params)
458
455
 
459
- node_obj = Puppet::Node.new(nodename, { :parameters => node_params, :facts => node_facts })
456
+ node_obj = Puppet::Node.new(nodename, { parameters: node_params, facts: node_facts })
460
457
 
461
458
  trusted_info = ['remote', nodename, trusted_facts_val]
462
- if Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0
463
- trusted_info.push(trusted_external_data)
464
- end
459
+ trusted_info.push(trusted_external_data) if Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0
465
460
  if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
466
461
  Puppet.push_context(
467
462
  {
468
- :trusted_information => Puppet::Context::TrustedInformation.new(*trusted_info)
463
+ trusted_information: Puppet::Context::TrustedInformation.new(*trusted_info)
469
464
  },
470
- "Context for spec trusted hash"
465
+ 'Context for spec trusted hash'
471
466
  )
472
467
 
473
468
  node_obj.add_server_facts(server_facts_hash) if RSpec.configuration.trusted_server_facts
@@ -479,7 +474,7 @@ module RSpec::Puppet
479
474
  def stub_facts!(facts)
480
475
  Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign
481
476
  FacterImpl.clear
482
- facts.each { |k, v| FacterImpl.add(k, :weight => 999) { setcode { v } } }
477
+ facts.each { |k, v| FacterImpl.add(k, weight: 999) { setcode { v } } }
483
478
  end
484
479
 
485
480
  def build_catalog(*args)
@@ -493,27 +488,31 @@ module RSpec::Puppet
493
488
  end
494
489
 
495
490
  def munge_facts(facts)
496
- return facts.reduce({}) do | memo, (k, v)|
497
- memo.tap { |m| m[k.to_s] = munge_facts(v) }
498
- end if facts.is_a? Hash
491
+ if facts.is_a? Hash
492
+ return facts.reduce({}) do |memo, (k, v)|
493
+ memo.tap { |m| m[k.to_s] = munge_facts(v) }
494
+ end
495
+ end
499
496
 
500
- return facts.reduce([]) do |memo, v|
501
- memo << munge_facts(v); memo
502
- end if facts.is_a? Array
497
+ if facts.is_a? Array
498
+ return facts.each_with_object([]) do |v, memo|
499
+ memo << munge_facts(v)
500
+ end
501
+ end
503
502
 
504
503
  facts
505
504
  end
506
505
 
507
506
  def escape_special_chars(string)
508
- string.gsub(/\$/, "\\$")
507
+ string.gsub(/\$/, '\\$')
509
508
  end
510
509
 
511
510
  def rspec_compatibility
512
- if RSpec::Version::STRING < '3'
513
- # RSpec 2 compatibility:
514
- alias_method :failure_message_for_should, :failure_message
515
- alias_method :failure_message_for_should_not, :failure_message_when_negated
516
- end
511
+ return unless RSpec::Version::STRING < '3'
512
+
513
+ # RSpec 2 compatibility:
514
+ alias_method :failure_message_for_should, :failure_message
515
+ alias_method :failure_message_for_should_not, :failure_message_when_negated
517
516
  end
518
517
 
519
518
  def fixture_spec_hiera_conf(mod)
@@ -540,7 +539,7 @@ module RSpec::Puppet
540
539
  # @param [String] title reference title
541
540
  # @return [RSpec::Puppet::RawString] return a new RawString with the type/title populated correctly
542
541
  def ref(type, title)
543
- return RSpec::Puppet::RawString.new("#{type}['#{title}']")
542
+ RSpec::Puppet::RawString.new("#{type}['#{title}']")
544
543
  end
545
544
 
546
545
  # Helper to return value wrapped in Sensitive type.
@@ -548,7 +547,7 @@ module RSpec::Puppet
548
547
  # @param [Object] value to wrap
549
548
  # @return [RSpec::Puppet::Sensitive] a new Sensitive wrapper with the new value
550
549
  def sensitive(value)
551
- return RSpec::Puppet::Sensitive.new(value)
550
+ RSpec::Puppet::Sensitive.new(value)
552
551
  end
553
552
 
554
553
  # @!attribute [r] adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'open3'
3
5
  require 'json'
@@ -17,7 +19,7 @@ task :release_test do
17
19
  'garethr/garethr-docker',
18
20
  'sensu/sensu-puppet',
19
21
  'jenkinsci/puppet-jenkins',
20
- 'rnelson0/puppet-local_user',
22
+ 'rnelson0/puppet-local_user'
21
23
  ]
22
24
 
23
25
  Bundler.with_clean_env do
@@ -61,7 +63,8 @@ task :release_test do
61
63
  end
62
64
 
63
65
  print ' Running baseline tests... '
64
- baseline_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
66
+ baseline_output, _, status = Open3.capture3({ 'SPEC_OPTS' => '--format json' }, 'bundle', 'exec', 'rake',
67
+ 'spec')
65
68
  if status.success?
66
69
  puts 'Done'
67
70
  else
@@ -94,12 +97,12 @@ task :release_test do
94
97
  if status.success?
95
98
  puts 'Done'
96
99
  else
97
- puts "FAILED"
100
+ puts 'FAILED'
98
101
  next
99
102
  end
100
103
 
101
104
  print ' Running tests against rspec-puppet HEAD... '
102
- head_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
105
+ head_output, _, status = Open3.capture3({ 'SPEC_OPTS' => '--format json' }, 'bundle', 'exec', 'rake', 'spec')
103
106
  if status.success?
104
107
  puts 'Done'
105
108
  else
@@ -114,7 +117,7 @@ task :release_test do
114
117
  puts 'FAILED'
115
118
  end
116
119
 
117
- json_regex = %r{\{(?:[^{}]|(?:\g<0>))*\}}x
120
+ json_regex = /\{(?:[^{}]|(?:\g<0>))*\}/x
118
121
  baseline_results = JSON.parse(baseline_output.scan(json_regex).find { |r| r.include?('summary_line') })
119
122
  head_results = JSON.parse(head_output.scan(json_regex).find { |r| r.include?('summary_line') })
120
123
  if head_results['summary_line'] == baseline_results['summary_line']
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecPuppet
4
+ VERSION = '3.0.0.rc.1'
5
+ end