rspec-puppet 2.12.0 → 3.0.0.rc.1

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.
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
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
1
  # RSpec tests for your Puppet manifests & modules
2
- [![Build Status](https://travis-ci.org/rodjek/rspec-puppet.svg?branch=master)](https://travis-ci.org/rodjek/rspec-puppet)
3
- [![Coverage Status](https://coveralls.io/repos/rodjek/rspec-puppet/badge.svg?branch=master)](https://coveralls.io/r/rodjek/rspec-puppet?branch=master)
4
2
 
5
3
  #### Table of Contents
6
4
 
@@ -617,6 +615,11 @@ be translated to `undef` when compiling. For example:
617
615
  let(:params) { {'user' => :undef, ...} }
618
616
  ```
619
617
 
618
+ For passing a sensitive value you can use the sensitive function with a value in brackets. For example
619
+ ```ruby
620
+ let(:params) { {'password' =>sensitive('secret') } }
621
+ ```
622
+
620
623
  For references to nodes or resources as seen when using `require` or `before` properties,
621
624
  or an `application` resource you can pass the string as an argument to the `ref` helper:
622
625
 
@@ -982,8 +985,17 @@ Some complex functions require access to the current parser's scope, e.g. for
982
985
  stubbing other parts of the system.
983
986
 
984
987
  ```ruby
985
- before(:each) { scope.expects(:lookupvar).with('some_variable').returns('some_value') }
986
- it { is_expected.to run.with_params('...').and_return('...') }
988
+ context 'when called with top-scope vars foo and bar set' do
989
+ before do
990
+ # :lookupvar is the method on scope that puppet calls internally to
991
+ # resolve the value of a variable.
992
+ allow(scope).to receive(:lookupvar).and_call_original
993
+ allow(scope).to receive(:lookupvar).with('::foo').and_return('Hello')
994
+ allow(scope).to receive(:lookupvar).with('::bar').and_return('World')
995
+ end
996
+
997
+ it { is_expected.to run.with_params().and_return('Hello World') }
998
+ end
987
999
  ```
988
1000
 
989
1001
  Note that this does not work when testing manifests which use custom functions. Instead,
@@ -1115,4 +1127,5 @@ be excluded from the coverage report.
1115
1127
  * [rspec-puppet-osmash](https://github.com/Aethylred/rspec-puppet-osmash): Provides Operation System hashes and validations for rspec-puppet
1116
1128
  * [puppet_spec_facts](https://github.com/danieldreier/puppet_spec_facts): Gem to provide puppet fact hashes for rspec-puppet testing
1117
1129
 
1118
- For a list of other module development tools see https://puppet.community/plugins/
1130
+ For a list of other module development tools see https://voxpupuli.org/plugins/
1131
+
@@ -1,16 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
5
 
5
6
  require 'rspec-puppet'
6
7
  require 'optparse'
7
8
 
8
9
  options = {
9
- :module_name => nil,
10
+ module_name: nil
10
11
  }
11
12
 
12
13
  OptionParser.new do |opts|
13
- opts.banner = "Usage: rspec-puppet-init [options]"
14
+ opts.banner = 'Usage: rspec-puppet-init [options]'
14
15
 
15
16
  opts.on('-n', '--name NAME', 'The name of the module (override autodetection)') do |v|
16
17
  options[:module_name] = v
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec-puppet/facter_impl'
2
4
 
3
5
  module RSpec::Puppet
4
6
  module Adapters
5
-
6
7
  class Base
7
8
  # Set up all Puppet settings applicable for this Puppet version as
8
9
  # application defaults.
@@ -44,12 +45,16 @@ module RSpec::Puppet
44
45
  settings = settings_map.map do |puppet_setting, rspec_setting|
45
46
  [puppet_setting, get_setting(example_group, rspec_setting)]
46
47
  end.flatten
47
- default_hash = {:confdir => '/dev/null', :vardir => '/dev/null' }
48
+ default_hash = { confdir: '/dev/null', vardir: '/dev/null' }
48
49
  if defined?(Puppet::Test::TestHelper) && Puppet::Test::TestHelper.respond_to?(:app_defaults_for_tests, true)
49
50
  default_hash.merge!(Puppet::Test::TestHelper.send(:app_defaults_for_tests))
50
51
  end
51
52
  settings_hash = default_hash.merge(Hash[*settings])
52
- settings_hash.inject(settings_hash) { |h, (k, v)| h[k] = (v == '/dev/null') ? 'c:/nul/' : v; h } if Gem.win_platform?
53
+ if Gem.win_platform?
54
+ settings_hash.each_with_object(settings_hash) do |(k, v), h|
55
+ h[k] = v == '/dev/null' ? 'c:/nul/' : v
56
+ end
57
+ end
53
58
 
54
59
  if Puppet.settings.respond_to?(:initialize_app_defaults)
55
60
  Puppet.settings.initialize_app_defaults(settings_hash)
@@ -83,7 +88,7 @@ module RSpec::Puppet
83
88
  # Use the compiler directly to skip the filtering done by the indirector
84
89
  Puppet::Parser::Compiler.compile(node).filter { |r| !r.exported? }
85
90
  else
86
- Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node)
91
+ Puppet::Resource::Catalog.indirection.find(node.name, use_node: node)
87
92
  end
88
93
  end
89
94
 
@@ -93,9 +98,9 @@ module RSpec::Puppet
93
98
 
94
99
  def settings_map
95
100
  [
96
- [:modulepath, :module_path],
97
- [:config, :config],
98
- [:confdir, :confdir],
101
+ %i[modulepath module_path],
102
+ %i[config config],
103
+ %i[confdir confdir]
99
104
  ]
100
105
  end
101
106
 
@@ -128,15 +133,15 @@ module RSpec::Puppet
128
133
  def setup_puppet(example_group)
129
134
  super
130
135
 
131
- if rspec_modulepath = RSpec.configuration.module_path
132
- modulepath = rspec_modulepath.split(File::PATH_SEPARATOR)
133
- else
134
- modulepath = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
135
- File.join(path, 'fixtures', 'modules')
136
- end
137
- end
136
+ modulepath = if (rspec_modulepath = RSpec.configuration.module_path)
137
+ rspec_modulepath.split(File::PATH_SEPARATOR)
138
+ else
139
+ Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
140
+ File.join(path, 'fixtures', 'modules')
141
+ end
142
+ end
138
143
 
139
- if rspec_manifest = RSpec.configuration.manifest
144
+ if (rspec_manifest = RSpec.configuration.manifest)
140
145
  manifest = rspec_manifest
141
146
  else
142
147
  manifest_paths = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
@@ -155,28 +160,31 @@ module RSpec::Puppet
155
160
 
156
161
  Puppet.push_context(
157
162
  {
158
- :environments => loader,
159
- :current_environment => env,
160
- :loaders => (Puppet::Pops::Loaders.new(env) if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0')),
163
+ environments: loader,
164
+ current_environment: env,
165
+ loaders: (Puppet::Pops::Loaders.new(env) if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0'))
161
166
  },
162
- "Setup rspec-puppet environments"
167
+ 'Setup rspec-puppet environments'
163
168
  )
164
169
  end
165
170
 
166
171
  def settings_map
167
- super.concat([
168
- [:environmentpath, :environmentpath],
169
- [:hiera_config, :hiera_config],
170
- [:strict_variables, :strict_variables],
171
- [:manifest, :manifest],
172
- ])
172
+ super.push(
173
+ %i[environmentpath environmentpath],
174
+ %i[hiera_config hiera_config],
175
+ %i[strict_variables strict_variables],
176
+ %i[manifest manifest]
177
+ )
173
178
  end
174
179
 
175
180
  def catalog(node, exported)
176
181
  node.environment = current_environment
177
182
  # Override $::environment to workaround PUP-5835, where Puppet otherwise
178
183
  # stores a symbol for the parameter
179
- node.parameters['environment'] = current_environment.name.to_s if node.parameters['environment'] != node.parameters['environment'].to_s
184
+ if node.parameters['environment'] != node.parameters['environment'].to_s
185
+ node.parameters['environment'] =
186
+ current_environment.name.to_s
187
+ end
180
188
  super
181
189
  end
182
190
 
@@ -210,9 +218,9 @@ module RSpec::Puppet
210
218
  end
211
219
 
212
220
  def settings_map
213
- super.concat([
214
- [:trusted_server_facts, :trusted_server_facts]
215
- ])
221
+ super.push(
222
+ %i[trusted_server_facts trusted_server_facts]
223
+ )
216
224
  end
217
225
  end
218
226
 
@@ -229,7 +237,7 @@ module RSpec::Puppet
229
237
  begin
230
238
  Puppet.runtime[:facter]
231
239
  @supports_facter_runtime = true
232
- rescue
240
+ rescue StandardError
233
241
  @supports_facter_runtime = false
234
242
  end
235
243
  end
@@ -260,10 +268,10 @@ module RSpec::Puppet
260
268
  end
261
269
 
262
270
  def settings_map
263
- super.concat([
264
- [:basemodulepath, :basemodulepath],
265
- [:vendormoduledir, :vendormoduledir],
266
- ])
271
+ super.push(
272
+ %i[basemodulepath basemodulepath],
273
+ %i[vendormoduledir vendormoduledir]
274
+ )
267
275
  end
268
276
 
269
277
  def catalog(node, _exported)
@@ -275,55 +283,55 @@ module RSpec::Puppet
275
283
 
276
284
  class Adapter30 < Base
277
285
  def settings_map
278
- super.concat([
279
- [:manifestdir, :manifest_dir],
280
- [:manifest, :manifest],
281
- [:templatedir, :template_dir],
282
- [:hiera_config, :hiera_config],
283
- ])
286
+ super.push(
287
+ %i[manifestdir manifest_dir],
288
+ %i[manifest manifest],
289
+ %i[templatedir template_dir],
290
+ %i[hiera_config hiera_config]
291
+ )
284
292
  end
285
293
  end
286
294
 
287
295
  class Adapter32 < Adapter30
288
296
  def settings_map
289
- super.concat([
290
- [:parser, :parser],
291
- ])
297
+ super.push(
298
+ %i[parser parser]
299
+ )
292
300
  end
293
301
  end
294
302
 
295
303
  class Adapter33 < Adapter32
296
304
  def settings_map
297
- super.concat([
298
- [:ordering, :ordering],
299
- [:stringify_facts, :stringify_facts],
300
- ])
305
+ super.push(
306
+ %i[ordering ordering],
307
+ %i[stringify_facts stringify_facts]
308
+ )
301
309
  end
302
310
  end
303
311
 
304
312
  class Adapter34 < Adapter33
305
313
  def settings_map
306
- super.concat([
307
- [:trusted_node_data, :trusted_node_data],
308
- ])
314
+ super.push(
315
+ %i[trusted_node_data trusted_node_data]
316
+ )
309
317
  end
310
318
  end
311
319
 
312
320
  class Adapter35 < Adapter34
313
321
  def settings_map
314
- super.concat([
315
- [:strict_variables, :strict_variables],
316
- ])
322
+ super.push(
323
+ %i[strict_variables strict_variables]
324
+ )
317
325
  end
318
326
  end
319
327
 
320
328
  class Adapter27 < Base
321
329
  def settings_map
322
- super.concat([
323
- [:manifestdir, :manifest_dir],
324
- [:manifest, :manifest],
325
- [:templatedir, :template_dir],
326
- ])
330
+ super.push(
331
+ %i[manifestdir manifest_dir],
332
+ %i[manifest manifest],
333
+ %i[templatedir template_dir]
334
+ )
327
335
  end
328
336
  end
329
337
 
@@ -339,9 +347,7 @@ module RSpec::Puppet
339
347
  ['3.0', Adapter30],
340
348
  ['2.7', Adapter27]
341
349
  ].each do |(version, klass)|
342
- if Puppet::Util::Package.versioncmp(Puppet.version, version) >= 0
343
- return klass.new
344
- end
350
+ return klass.new if Puppet::Util::Package.versioncmp(Puppet.version, version) >= 0
345
351
  end
346
352
  raise "Puppet version #{Puppet.version} is not supported."
347
353
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec::Puppet
2
4
  class Cache
3
-
4
5
  MAX_ENTRIES = 16
5
6
 
6
7
  # @param [Proc] default_proc The default proc to use to fetch objects on cache miss
@@ -12,7 +13,7 @@ module RSpec::Puppet
12
13
 
13
14
  def get(*args, &blk)
14
15
  key = Marshal.load(Marshal.dump(args))
15
- if @cache.has_key?(key)
16
+ if @cache.key?(key)
16
17
  # Cache hit
17
18
  # move that entry last to make it "most recenty used"
18
19
  @lra.insert(-1, @lra.delete_at(@lra.index(args)))
@@ -1,27 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec::Puppet::Consts
2
4
  STUBBED_CONSTS = {
3
- :posix => {
5
+ posix: {
4
6
  'File::PATH_SEPARATOR' => ':',
5
7
  'File::ALT_SEPARATOR' => nil,
6
- 'Pathname::SEPARATOR_PAT' => /#{Regexp.quote('/')}/,
8
+ 'Pathname::SEPARATOR_PAT' => /#{Regexp.quote('/')}/
7
9
  },
8
- :windows => {
10
+ windows: {
9
11
  'File::PATH_SEPARATOR' => ';',
10
- 'File::ALT_SEPARATOR' => "\\",
11
- 'Pathname::SEPARATOR_PAT' => /[#{Regexp.quote("\\")}#{Regexp.quote('/')}]/,
12
+ 'File::ALT_SEPARATOR' => '\\',
13
+ 'Pathname::SEPARATOR_PAT' => /[#{Regexp.quote("\\")}#{Regexp.quote('/')}]/
12
14
  }
13
- }
15
+ }.freeze
14
16
 
15
17
  FEATURES = {
16
- :posix => {
17
- :posix => true,
18
- :microsoft_windows => false,
19
- },
20
- :windows => {
21
- :posix => false,
22
- :microsoft_windows => true,
18
+ posix: {
19
+ posix: true,
20
+ microsoft_windows: false
23
21
  },
24
- }
22
+ windows: {
23
+ posix: false,
24
+ microsoft_windows: true
25
+ }
26
+ }.freeze
25
27
 
26
28
  def self.stub_consts_for(platform)
27
29
  STUBBED_CONSTS[platform].each do |const_name, const_value|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tmpdir'
2
4
  require 'digest'
3
5
  require 'json'
@@ -16,23 +18,22 @@ end
16
18
 
17
19
  module RSpec::Puppet
18
20
  class Coverage
19
-
20
21
  attr_accessor :filters, :filters_regex
21
22
 
22
23
  class << self
23
24
  extend Forwardable
24
25
 
25
- delegated_methods = [
26
- :instance,
27
- :add,
28
- :cover!,
29
- :report!,
30
- :filters,
31
- :filters_regex,
32
- :add_filter,
33
- :add_filter_regex,
34
- :add_from_catalog,
35
- :results,
26
+ delegated_methods = %i[
27
+ instance
28
+ add
29
+ cover!
30
+ report!
31
+ filters
32
+ filters_regex
33
+ add_filter
34
+ add_filter_regex
35
+ add_from_catalog
36
+ results
36
37
  ]
37
38
 
38
39
  def_delegators(*delegated_methods)
@@ -112,23 +113,21 @@ module RSpec::Puppet
112
113
  end
113
114
 
114
115
  def add(resource)
115
- if !exists?(resource) && !filtered?(resource)
116
- @collection[resource.to_s] = ResourceWrapper.new(resource)
117
- end
116
+ return unless !exists?(resource) && !filtered?(resource)
117
+
118
+ @collection[resource.to_s] = ResourceWrapper.new(resource)
118
119
  end
119
120
 
120
121
  def add_filter(type, title)
121
122
  type = capitalize_name(type)
122
123
 
123
- if type == 'Class'
124
- title = capitalize_name(title)
125
- end
124
+ title = capitalize_name(title) if type == 'Class'
126
125
 
127
126
  @filters << "#{type}[#{title}]"
128
127
  end
129
128
 
130
129
  def add_filter_regex(type, pattern)
131
- raise ArgumentError.new('pattern argument must be a Regexp') unless pattern.is_a?(Regexp)
130
+ raise ArgumentError, 'pattern argument must be a Regexp' unless pattern.is_a?(Regexp)
132
131
 
133
132
  type = capitalize_name(type)
134
133
 
@@ -145,7 +144,7 @@ module RSpec::Puppet
145
144
 
146
145
  # match an even number of backslashes before the anchor - this indicates that the anchor was not escaped
147
146
  # note the necessity for the negative lookbehind `(?<!)` to assert that there is no backslash before this
148
- src = if src.match(/(?<!\\)(\\\\)*(?:\\[zZ]|\$)\z/)
147
+ src = if /(?<!\\)(\\\\)*(?:\\[zZ]|\$)\z/.match?(src)
149
148
  src.gsub(/(?:\\[zZ]|\$)\z/, '')
150
149
  else
151
150
  # no anchor at the end
@@ -157,7 +156,9 @@ module RSpec::Puppet
157
156
 
158
157
  # add all resources from catalog declared in module test_module
159
158
  def add_from_catalog(catalog, test_module)
160
- coverable_resources = catalog.to_a.reject { |resource| !test_module.nil? && filter_resource?(resource, test_module) }
159
+ coverable_resources = catalog.to_a.reject do |resource|
160
+ !test_module.nil? && filter_resource?(resource, test_module)
161
+ end
161
162
  coverable_resources.each do |resource|
162
163
  add(resource)
163
164
  end
@@ -171,9 +172,9 @@ module RSpec::Puppet
171
172
  end
172
173
 
173
174
  def cover!(resource)
174
- if !filtered?(resource) && (wrapper = find(resource))
175
- wrapper.touch!
176
- end
175
+ return unless !filtered?(resource) && (wrapper = find(resource))
176
+
177
+ wrapper.touch!
177
178
  end
178
179
 
179
180
  def report!(coverage_desired = nil)
@@ -213,9 +214,9 @@ module RSpec::Puppet
213
214
  coverage_desired ||= 0
214
215
 
215
216
  if coverage_desired.is_a?(Numeric) && coverage_desired.to_f <= 100.00 && coverage_desired.to_f >= 0.0
216
- coverage_test = RSpec.describe("Code coverage")
217
+ coverage_test = RSpec.describe('Code coverage')
217
218
  coverage_results = coverage_test.example("must cover at least #{coverage_desired}% of resources") do
218
- expect( coverage_actual.to_f ).to be >= coverage_desired.to_f
219
+ expect(coverage_actual.to_f).to be >= coverage_desired.to_f
219
220
  end
220
221
  coverage_test.run(RSpec.configuration.reporter)
221
222
 
@@ -248,8 +249,8 @@ module RSpec::Puppet
248
249
  report[:touched] = @collection.count { |_, resource| resource.touched? }
249
250
  report[:untouched] = report[:total] - report[:touched]
250
251
 
251
- coverage = report[:total].to_f > 0 ? ((report[:touched].to_f / report[:total].to_f) * 100) : 100.0
252
- report[:coverage] = "%5.2f" % coverage
252
+ coverage = report[:total].to_f.positive? ? ((report[:touched].to_f / report[:total]) * 100) : 100.0
253
+ report[:coverage] = '%5.2f' % coverage
253
254
 
254
255
  report[:resources] = Hash[*@collection.map do |name, wrapper|
255
256
  [name, wrapper.to_hash]
@@ -258,10 +259,10 @@ module RSpec::Puppet
258
259
  text = [
259
260
  "Total resources: #{report[:total]}",
260
261
  "Touched resources: #{report[:touched]}",
261
- "Resource coverage: #{report[:coverage]}%",
262
+ "Resource coverage: #{report[:coverage]}%"
262
263
  ]
263
264
 
264
- if report[:untouched] > 0
265
+ if (report[:untouched]).positive?
265
266
  text += ['', 'Untouched resources:']
266
267
  untouched_resources = report[:resources].reject { |_, r| r[:touched] }
267
268
  text += untouched_resources.map { |name, _| " #{name}" }.sort
@@ -288,25 +289,19 @@ module RSpec::Puppet
288
289
  # @param test_module [String] The name of the module under test
289
290
  # @return [true, false]
290
291
  def filter_resource?(resource, test_module)
291
- if filtered?(resource)
292
- return true
293
- end
292
+ return true if filtered?(resource)
294
293
 
295
294
  if resource.type == 'Class'
296
295
  module_name = resource.title.split('::').first.downcase
297
- if module_name != test_module
298
- return true
299
- end
296
+ return true if module_name != test_module
300
297
  end
301
298
 
302
299
  if resource.file
303
300
  paths = module_paths(test_module)
304
- unless paths.any? { |path| resource.file.include?(path) }
305
- return true
306
- end
301
+ return true unless paths.any? { |path| resource.file.include?(path) }
307
302
  end
308
303
 
309
- return false
304
+ false
310
305
  end
311
306
 
312
307
  # Find all paths that may contain testable resources for a module.
@@ -330,7 +325,7 @@ module RSpec::Puppet
330
325
  end
331
326
 
332
327
  def capitalize_name(name)
333
- name.split('::').map { |subtitle| subtitle.capitalize }.join('::')
328
+ name.split('::').map(&:capitalize).join('::')
334
329
  end
335
330
 
336
331
  class ResourceWrapper
@@ -346,7 +341,7 @@ module RSpec::Puppet
346
341
 
347
342
  def to_hash
348
343
  {
349
- :touched => touched?,
344
+ touched: touched?
350
345
  }
351
346
  end
352
347
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec::Puppet
2
4
  module Errors
3
5
  class MatchError < StandardError
@@ -11,18 +13,16 @@ module RSpec::Puppet
11
13
  end
12
14
 
13
15
  def message
14
- if @param.to_s == 'content' and expected.is_a?( String )
16
+ if (@param.to_s == 'content') && expected.is_a?(String)
15
17
  if negative == true
16
18
  "#{param} not set to supplied string"
17
19
  else
18
20
  "#{param} set to supplied string"
19
21
  end
22
+ elsif negative == true
23
+ "#{param} not set to #{expected.inspect} but it is set to #{actual.inspect}"
20
24
  else
21
- if negative == true
22
- "#{param} not set to #{expected.inspect} but it is set to #{actual.inspect}"
23
- else
24
- "#{param} set to #{expected.inspect} but it is set to #{actual.inspect}"
25
- end
25
+ "#{param} set to #{expected.inspect} but it is set to #{actual.inspect}"
26
26
  end
27
27
  end
28
28
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec::Puppet
2
4
  # This module provides support for the application type
3
5
  module ApplicationExampleGroup
@@ -9,7 +11,7 @@ module RSpec::Puppet
9
11
  end
10
12
 
11
13
  def exported_resources
12
- lambda { load_catalogue(:application, true) }
14
+ -> { load_catalogue(:application, true) }
13
15
  end
14
16
 
15
17
  def rspec_puppet_cleanup
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec::Puppet
2
4
  module ClassExampleGroup
3
5
  include RSpec::Puppet::ManifestMatchers
@@ -8,7 +10,7 @@ module RSpec::Puppet
8
10
  end
9
11
 
10
12
  def exported_resources
11
- lambda { load_catalogue(:class, true) }
13
+ -> { load_catalogue(:class, true) }
12
14
  end
13
15
 
14
16
  def rspec_puppet_cleanup
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec::Puppet
2
4
  module DefineExampleGroup
3
5
  include RSpec::Puppet::ManifestMatchers
@@ -8,7 +10,7 @@ module RSpec::Puppet
8
10
  end
9
11
 
10
12
  def exported_resources
11
- lambda { load_catalogue(:define, true) }
13
+ -> { load_catalogue(:define, true) }
12
14
  end
13
15
 
14
16
  def rspec_puppet_cleanup