puppetlabs_spec_helper 9.0.0 → 9.0.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.
@@ -0,0 +1,401 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'rake check:dot_underscore', type: :task do
6
+ context 'when no ._ files are present' do
7
+ it 'runs without raising an error' do
8
+ expect { task.execute }.not_to raise_error
9
+ end
10
+ end
11
+
12
+ context 'when ._ files are present' do
13
+ before do
14
+ FileUtils.touch('._somefile')
15
+ end
16
+
17
+ it 'raises an error' do
18
+ expect { task.execute }
19
+ .to raise_error(/\._/)
20
+ .and output(a_string_including('._somefile')).to_stdout
21
+ end
22
+ end
23
+ end
24
+
25
+ describe 'rake check:git_ignore', type: :task do
26
+ context 'when no ignored files are committed' do
27
+ before do
28
+ `true` # ensure $CHILD_STATUS is a real successful status
29
+ allow_any_instance_of(Object).to receive(:`).with('git ls-files --ignored --exclude-standard --cached').and_return('')
30
+ end
31
+
32
+ it 'runs without raising an error' do
33
+ expect { task.execute }.not_to raise_error
34
+ end
35
+ end
36
+
37
+ context 'when ignored files are committed' do
38
+ before do
39
+ `true` # ensure $CHILD_STATUS is a real successful status
40
+ allow_any_instance_of(Object).to receive(:`).with('git ls-files --ignored --exclude-standard --cached').and_return("ignored_file.txt\n")
41
+ end
42
+
43
+ it 'raises an error' do
44
+ expect { task.execute }
45
+ .to raise_error(/gitignore.*committed/i)
46
+ .and output(a_string_including('ignored_file.txt')).to_stdout
47
+ end
48
+ end
49
+
50
+ context 'when git ls-files fails' do
51
+ before do
52
+ `false` # ensure $CHILD_STATUS is a real failed status
53
+ allow_any_instance_of(Object).to receive(:`).with('git ls-files --ignored --exclude-standard --cached').and_return('')
54
+ end
55
+
56
+ it 'raises an error' do
57
+ expect { task.execute }.to raise_error(/git ls-files failed/)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe 'rake compute_dev_version', type: :task do
63
+ before do
64
+ `true` # ensure $CHILD_STATUS is a real successful status
65
+ allow_any_instance_of(Object).to receive(:`).with('git rev-parse HEAD').and_return("abc12345\n")
66
+ allow_any_instance_of(Object).to receive(:`).with('git rev-parse --abbrev-ref HEAD').and_return("main\n")
67
+ end
68
+
69
+ context 'when metadata.json exists' do
70
+ before do
71
+ File.write('metadata.json', '{"version":"1.2.3"}')
72
+ end
73
+
74
+ it 'prints the dev version including the module version' do
75
+ expect { task.execute }.to output(a_string_including('1.2.3')).to_stdout
76
+ end
77
+
78
+ it 'prints the dev version including the short sha' do
79
+ expect { task.execute }.to output(a_string_including('abc12345')).to_stdout
80
+ end
81
+
82
+ context 'when BUILD_NUMBER env is set' do
83
+ before do
84
+ allow(ENV).to receive(:fetch).and_call_original
85
+ allow(ENV).to receive(:fetch).with('BUILD_NUMBER', nil).and_return('7')
86
+ end
87
+
88
+ it 'includes the zero-padded build number in the version' do
89
+ expect { task.execute }.to output(a_string_matching(/1\.2\.3-\d{4}-/)).to_stdout
90
+ end
91
+ end
92
+
93
+ context 'when BUILD_NUMBER env is set and branch is release' do
94
+ before do
95
+ allow(ENV).to receive(:fetch).and_call_original
96
+ allow(ENV).to receive(:fetch).with('BUILD_NUMBER', nil).and_return('7')
97
+ allow_any_instance_of(Object).to receive(:`).with('git rev-parse --abbrev-ref HEAD').and_return('release')
98
+ end
99
+
100
+ it 'uses the release version format with r prefix' do
101
+ expect { task.execute }.to output(a_string_matching(/1\.2\.3-r\d{4}-/)).to_stdout
102
+ end
103
+ end
104
+ end
105
+
106
+ context 'when only Modulefile exists (lines 203-204)' do
107
+ before do
108
+ File.write('Modulefile', "\nversion '2.3.4'\n")
109
+ end
110
+
111
+ it 'reads the version from Modulefile' do
112
+ expect { task.execute }.to output(a_string_including('2.3.4')).to_stdout
113
+ end
114
+ end
115
+
116
+ context 'when neither metadata.json nor Modulefile exists' do
117
+ it 'raises an error' do
118
+ expect { task.execute }.to raise_error(/metadata\.json or Modulefile/)
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'rake spec:simplecov', type: :task do
124
+ before do
125
+ allow(Rake::Task[:spec]).to receive(:execute)
126
+ end
127
+
128
+ after do
129
+ ENV.delete('SIMPLECOV')
130
+ end
131
+
132
+ it 'sets SIMPLECOV env variable before running spec' do
133
+ task.execute
134
+ expect(ENV.fetch('SIMPLECOV', nil)).to eq('yes')
135
+ end
136
+ end
137
+
138
+ describe 'rake spec', type: :task do
139
+ before do
140
+ allow(Rake::Task[:spec_prep]).to receive(:invoke)
141
+ allow(Rake::Task[:spec_standalone]).to receive(:invoke)
142
+ allow(Rake::Task[:spec_clean]).to receive(:invoke)
143
+ allow(Rake::Task[:spec_clean_symlinks]).to receive(:invoke)
144
+ end
145
+
146
+ it 'invokes spec_prep then spec_standalone then spec_clean' do
147
+ expect(Rake::Task[:spec_prep]).to receive(:invoke).ordered
148
+ expect(Rake::Task[:spec_standalone]).to receive(:invoke).ordered
149
+ expect(Rake::Task[:spec_clean]).to receive(:invoke).ordered
150
+ task.execute
151
+ end
152
+
153
+ it 'always invokes spec_clean_symlinks in the ensure block' do
154
+ allow(Rake::Task[:spec_standalone]).to receive(:invoke).and_raise(RuntimeError, 'spec failed')
155
+ expect(Rake::Task[:spec_clean_symlinks]).to receive(:invoke)
156
+ expect { task.execute }.to raise_error(RuntimeError)
157
+ end
158
+ end
159
+
160
+ describe 'rake parallel_spec', type: :task do
161
+ before do
162
+ allow(Rake::Task[:spec_prep]).to receive(:invoke)
163
+ allow(Rake::Task[:parallel_spec_standalone]).to receive(:invoke)
164
+ allow(Rake::Task[:spec_clean]).to receive(:invoke)
165
+ allow(Rake::Task[:spec_clean_symlinks]).to receive(:invoke)
166
+ end
167
+
168
+ it 'invokes spec_prep, parallel_spec_standalone, and spec_clean' do
169
+ expect(Rake::Task[:spec_prep]).to receive(:invoke)
170
+ expect(Rake::Task[:parallel_spec_standalone]).to receive(:invoke)
171
+ expect(Rake::Task[:spec_clean]).to receive(:invoke)
172
+ task.execute
173
+ end
174
+
175
+ it 'always invokes spec_clean_symlinks in the ensure block' do
176
+ allow(Rake::Task[:parallel_spec_standalone]).to receive(:invoke).and_raise(RuntimeError, 'failed')
177
+ expect(Rake::Task[:spec_clean_symlinks]).to receive(:invoke)
178
+ expect { task.execute }.to raise_error(RuntimeError)
179
+ end
180
+ end
181
+
182
+ describe 'rake release_checks', type: :task do
183
+ before do
184
+ allow(Rake::Task[:lint]).to receive(:invoke)
185
+ allow(Rake::Task[:validate]).to receive(:invoke)
186
+ allow(Rake::Task[:spec]).to receive(:invoke)
187
+ allow(Rake::Task[:parallel_spec]).to receive(:invoke)
188
+ allow(Rake::Task[:check]).to receive(:invoke)
189
+ end
190
+
191
+ it 'runs without raising an error' do
192
+ expect { task.execute }.not_to raise_error
193
+ end
194
+
195
+ it 'invokes lint and validate' do
196
+ expect(Rake::Task[:lint]).to receive(:invoke)
197
+ expect(Rake::Task[:validate]).to receive(:invoke)
198
+ task.execute
199
+ end
200
+
201
+ it 'invokes check' do
202
+ expect(Rake::Task[:check]).to receive(:invoke)
203
+ task.execute
204
+ end
205
+ end
206
+
207
+ describe 'rake validate', type: :task do
208
+ before do
209
+ allow(Rake::Task[:syntax]).to receive(:invoke)
210
+ allow(ENV).to receive(:[]).and_call_original
211
+ end
212
+
213
+ context 'with no lib ruby files and no metadata.json or REFERENCE.md' do
214
+ it 'runs without raising an error' do
215
+ expect { task.execute }.not_to raise_error
216
+ end
217
+ end
218
+
219
+ context 'when metadata.json exists' do
220
+ before do
221
+ File.write('metadata.json', '{"name":"test-module"}')
222
+ end
223
+
224
+ it 'attempts metadata validation' do
225
+ # metadata_lint task may or may not be defined; either path should not crash
226
+ expect { task.execute }.not_to raise_error
227
+ end
228
+ end
229
+
230
+ context 'when metadata.json and metadata_lint task are both available' do
231
+ before do
232
+ File.write('metadata.json', '{"name":"test-module"}')
233
+ Rake::Task.define_task(:metadata_lint) { nil }
234
+ allow(Rake::Task[:metadata_lint]).to receive(:invoke)
235
+ end
236
+
237
+ after do
238
+ Rake.application.instance_variable_get(:@tasks).delete('metadata_lint')
239
+ end
240
+
241
+ it 'invokes metadata_lint' do
242
+ expect(Rake::Task[:metadata_lint]).to receive(:invoke)
243
+ task.execute
244
+ end
245
+ end
246
+
247
+ context 'when REFERENCE.md exists' do
248
+ before do
249
+ File.write('REFERENCE.md', '# Reference')
250
+ end
251
+
252
+ it 'attempts reference validation' do
253
+ expect { task.execute }.not_to raise_error
254
+ end
255
+ end
256
+
257
+ context 'when REFERENCE.md and strings:validate:reference task are both available' do
258
+ before do
259
+ File.write('REFERENCE.md', '# Reference')
260
+ Rake::Task.define_task('strings:validate:reference') { nil }
261
+ allow(Rake::Task['strings:validate:reference']).to receive(:invoke)
262
+ end
263
+
264
+ after do
265
+ Rake.application.instance_variable_get(:@tasks).delete('strings:validate:reference')
266
+ end
267
+
268
+ it 'invokes strings:validate:reference' do
269
+ expect(Rake::Task['strings:validate:reference']).to receive(:invoke)
270
+ task.execute
271
+ end
272
+ end
273
+
274
+ context 'when lib/*.rb files exist (line 173)' do
275
+ before do
276
+ allow(Dir).to receive(:[]).and_call_original
277
+ allow(Dir).to receive(:[]).with('lib/**/*.rb').and_return(['lib/my_class.rb'])
278
+ # sh calls system() internally; stub it so no real subprocess is spawned
279
+ allow_any_instance_of(Object).to receive(:system).and_return(true)
280
+ end
281
+
282
+ it 'runs ruby -c on each lib file' do
283
+ expect { task.execute }.not_to raise_error
284
+ end
285
+ end
286
+ end
287
+
288
+ describe 'rake help', type: :task do
289
+ it 'calls system to list rake tasks' do
290
+ allow_any_instance_of(Object).to receive(:system).with('rake -T').and_return(true)
291
+ expect_any_instance_of(Object).to receive(:system).with('rake -T')
292
+ task.execute
293
+ end
294
+ end
295
+
296
+ describe 'rake spec_standalone', type: :task do
297
+ before do
298
+ # Prevent RSpec from actually running — we only want the configure block to run.
299
+ allow_any_instance_of(RSpec::Core::RakeTask).to receive(:run_task)
300
+ allow(ENV).to receive(:[]).and_call_original
301
+ allow(ENV).to receive(:[]).with('CI_SPEC_OPTIONS').and_return(nil)
302
+ allow(ENV).to receive(:[]).with('CI_NODE_TOTAL').and_return(nil)
303
+ allow(ENV).to receive(:[]).with('CI_NODE_INDEX').and_return(nil)
304
+ end
305
+
306
+ context 'without CI env vars and no extra args' do
307
+ it 'sets the default pattern (lines 51-53, 66-67)' do
308
+ expect { task.execute }.not_to raise_error
309
+ end
310
+ end
311
+
312
+ context 'without CI env vars but with extra args' do
313
+ it 'uses the extras as the pattern (line 69)' do
314
+ expect { task.execute(Rake::TaskArguments.new([], ['spec/unit/foo_spec.rb'])) }.not_to raise_error
315
+ end
316
+ end
317
+
318
+ context 'with CI env vars set to valid values' do
319
+ before do
320
+ allow(ENV).to receive(:[]).with('CI_NODE_TOTAL').and_return('2')
321
+ allow(ENV).to receive(:[]).with('CI_NODE_INDEX').and_return('1')
322
+ # Create a fake spec file so Rake::FileList finds at least one entry.
323
+ FileUtils.mkdir_p('spec/unit/fake')
324
+ File.write('spec/unit/fake/my_spec.rb', '')
325
+ end
326
+
327
+ it 'splits files across CI nodes (lines 54-61)' do
328
+ expect { task.execute }.not_to raise_error
329
+ end
330
+
331
+ context 'with extra args in CI mode' do
332
+ it 'uses the extras as the pattern (line 63)' do
333
+ expect { task.execute(Rake::TaskArguments.new([], ['spec/unit/fake/my_spec.rb'])) }.not_to raise_error
334
+ end
335
+ end
336
+ end
337
+ end
338
+
339
+ describe 'rake spec_list_json', type: :task do
340
+ before do
341
+ allow_any_instance_of(RSpec::Core::RakeTask).to receive(:run_task)
342
+ end
343
+
344
+ it 'configures dry-run JSON output (lines 76-77)' do
345
+ expect { task.execute }.not_to raise_error
346
+ end
347
+ end
348
+
349
+ describe 'rake parallel_spec_standalone', type: :task do
350
+ it 'raises when parallel_tests gem is not loaded (line 108)' do
351
+ expect { task.execute }.to raise_error(/parallel_tests gem/)
352
+ end
353
+ end
354
+
355
+ describe 'rake rubocop', type: :task do
356
+ before do
357
+ allow_any_instance_of(RuboCop::RakeTask).to receive(:run_cli)
358
+ allow(ENV).to receive(:[]).and_call_original
359
+ allow(ENV).to receive(:[]).with('GITHUB_ACTIONS').and_return('true')
360
+ allow(Gem::Specification).to receive(:find_by_name).with('rubocop').and_return(
361
+ instance_double(Gem::Specification, version: Gem::Version.new('1.64.1')),
362
+ )
363
+ end
364
+
365
+ it 'configures rubocop options and adds github formatter (lines 293, 296-298)' do
366
+ expect { task.execute }.not_to raise_error
367
+ end
368
+ end
369
+
370
+ describe 'create_gch_task' do
371
+ include Rake::DSL
372
+
373
+ # create_gch_task is a method defined in rake_tasks.rb. When
374
+ # github_changelog_generator is absent the else branch runs (lines 309, 369-371).
375
+ it 'defines a :changelog task that raises when gem is missing' do
376
+ create_gch_task
377
+ expect { Rake::Task[:changelog].execute }.to raise_error(/github_changelog_generator/)
378
+ end
379
+
380
+ context 'when github_changelog_generator gem is available' do
381
+ before do
382
+ allow(Bundler.rubygems).to receive(:find_name)
383
+ .with('github_changelog_generator')
384
+ .and_return([double('gemspec')])
385
+ allow(File).to receive(:read).with('metadata.json').and_return(
386
+ '{"author":"myuser","name":"mymodule","version":"1.0.0"}',
387
+ )
388
+ config = double('config').as_null_object
389
+ stub_const('GitHubChangelogGenerator::RakeTask', double('RakeTask'))
390
+ allow(GitHubChangelogGenerator::RakeTask).to receive(:new)
391
+ .with(:changelog)
392
+ .and_yield(config)
393
+ allow(ENV).to receive(:[]).and_call_original
394
+ allow(ENV).to receive(:[]).with('CHANGELOG_GITHUB_TOKEN').and_return('fake_token')
395
+ end
396
+
397
+ it 'defines a changelog task using gem configuration' do
398
+ expect { create_gch_task }.not_to raise_error
399
+ end
400
+ end
401
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetlabs_spec_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0
4
+ version: 9.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-08-20 00:00:00.000000000 Z
12
+ date: 2026-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mocha
@@ -111,14 +111,14 @@ dependencies:
111
111
  requirements:
112
112
  - - "~>"
113
113
  - !ruby/object:Gem::Version
114
- version: '5.0'
114
+ version: '6.0'
115
115
  type: :runtime
116
116
  prerelease: false
117
117
  version_requirements: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
- version: '5.0'
121
+ version: '6.0'
122
122
  - !ruby/object:Gem::Dependency
123
123
  name: voxpupuli-rubocop
124
124
  requirement: !ruby/object:Gem::Requirement
@@ -158,10 +158,15 @@ files:
158
158
  - spec/acceptance/fixtures/Rakefile
159
159
  - spec/acceptance/smoke_spec.rb
160
160
  - spec/spec_helper.rb
161
+ - spec/unit/puppetlabs_spec_helper/module_spec_helper_spec.rb
162
+ - spec/unit/puppetlabs_spec_helper/puppetlabs_spec/files_spec.rb
163
+ - spec/unit/puppetlabs_spec_helper/puppetlabs_spec/fixtures_spec.rb
164
+ - spec/unit/puppetlabs_spec_helper/puppetlabs_spec/matchers_spec.rb
161
165
  - spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
162
166
  - spec/unit/puppetlabs_spec_helper/tasks/check_symlinks_spec.rb
163
167
  - spec/unit/puppetlabs_spec_helper/tasks/check_test_file_spec.rb
164
168
  - spec/unit/puppetlabs_spec_helper/tasks/fixture_helpers_spec.rb
169
+ - spec/unit/puppetlabs_spec_helper/tasks/rake_tasks_spec.rb
165
170
  - spec/watchr.rb
166
171
  homepage: http://github.com/puppetlabs/puppetlabs_spec_helper
167
172
  licenses: