Repository navigation
Expand file tree
/
Copy pathruby_gem_spec.rb
More file actions
527 lines (475 loc) · 25.8 KB
/
Copy pathruby_gem_spec.rb
File metadata and controls
527 lines (475 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# frozen_string_literal: true
require 'spec_helper'
require 'ruby-gem-release/workflow/ruby_gem'
require 'ruby-gem-release/changelog'
require 'ruby-gem-release/version/references'
RSpec.describe RubyGemRelease::Workflow::RubyGem do
let(:events) { [] }
let(:version) { instance_double(RubyGemRelease::Version::RubyConstant) }
let(:objects) do
{
changelog: instance_double(RubyGemRelease::Changelog::KeepAChangelog),
package: instance_double(RubyGemRelease::Package::RubyGem, built?: false),
destination: instance_double(RubyGemRelease::Destination::RubyGems),
git: instance_double(RubyGemRelease::SourceControl::Git),
hosting: instance_double(RubyGemRelease::Hosting::GitHubRelease)
}
end
around do |example|
application = Rake.application
environment = ENV.to_h
Rake.application = Rake::Application.new
ENV.update('RELEASE_VERSION' => '2.0.0', 'GEMSPEC_VERSION' => '1.2.3', 'RELEASE_DATE' => '2026-11-07', 'INPUT_VERSION' => '')
ENV.delete('GITHUB_OUTPUT')
%w[RELEASE_STATE_FILE RELEASE_STEP_ID RELEASE_STEPS_JSON RELEASE_DATA_DIR GEMSPEC_PATH GITHUB_ACTIONS].each { |key| ENV.delete(key) }
example.run
ensure
Rake.application = application
ENV.replace(environment)
end
before do
allow(version).to receive(:read) do
events << :read
'2.0.0'
end
allow(version).to receive(:increment!) do
events << :increment
'2.0.1'
end
allow(version).to receive(:set!)
record_operations(:changelog, %i[release! prepare_next!])
allow(objects.fetch(:changelog)).to receive_messages(pending?: true, released?: false)
record_operations(:package, [:build!])
record_operations(:destination, %i[authenticate! publish!])
allow(objects.fetch(:destination)).to receive(:authentication).and_return('rubygems')
record_operations(:git, %i[commit! tag! push! commit_next!])
allow(objects.fetch(:git)).to receive(:stage_changes!).and_yield
record_operations(:hosting, [:publish!])
allow(RubyGemRelease::Package::RubyGem).to receive(:new).and_return(objects.fetch(:package))
allow(RubyGemRelease::Destination::RubyGems).to receive(:new).and_return(objects.fetch(:destination))
allow(RubyGemRelease::SourceControl::Git).to receive(:new).and_return(objects.fetch(:git))
allow(RubyGemRelease::Hosting::GitHubRelease).to receive(:new).and_return(objects.fetch(:hosting))
end
def record_operations(object, methods)
methods.each do |method|
allow(objects.fetch(object)).to receive(method) { events << [object, method] }
end
end
def install(**overrides)
described_class.new(version: version, changelog: objects.fetch(:changelog), **overrides).install_tasks
end
def run_callbacks
%w[validate prepare publish bump].each { |phase| Rake::Task["release:#{phase}"].invoke }
end
it 'publishes the released changelog section as hosted release notes, read before any publication', :aggregate_failures do
allow(objects.fetch(:changelog)).to receive(:notes).with('2.0.0') do
events << %i[changelog notes]
'- Released notes.'
end
install
Rake::Task['release:publish'].invoke
expect(events.index(%i[changelog notes])).to be < events.index(%i[destination publish!])
expect(objects.fetch(:destination)).to have_received(:publish!).with(have_attributes(notes: nil), package: objects.fetch(:package))
expect(objects.fetch(:hosting)).to have_received(:publish!).with(have_attributes(version: '2.0.0', notes: '- Released notes.'), package: objects.fetch(:package))
end
it 'fails before publishing anything when the released changelog section cannot be read' do
allow(objects.fetch(:changelog)).to receive(:notes).and_raise(ArgumentError, 'empty release notes in CHANGELOG.md')
install
expect { Rake::Task['release:publish'].invoke }.to raise_error(ArgumentError, /empty release notes/)
expect(objects.fetch(:destination)).not_to have_received(:publish!)
expect(objects.fetch(:git)).not_to have_received(:commit!)
end
it 'keeps platform-generated notes for changelogs without readable notes and skips reading without hosting', :aggregate_failures do
install
Rake::Task['release:publish'].invoke
expect(objects.fetch(:hosting)).to have_received(:publish!).with(have_attributes(notes: nil), package: objects.fetch(:package))
Rake.application = Rake::Application.new
allow(objects.fetch(:changelog)).to receive(:notes)
install(hosting: nil)
Rake::Task['release:publish'].invoke
expect(objects.fetch(:changelog)).not_to have_received(:notes)
end
it 'rejects empty pending notes without invoking release operations' do
allow(objects.fetch(:changelog)).to receive(:pending?).and_return(false)
install
expect { Rake::Task['release:validate'].invoke }.to raise_error(ArgumentError, /Nothing to release/)
expect(events).to be_empty
end
it 'checkpoints the exact release before publication or authentication' do
install
Rake::Task['release:workflow:checkpoint'].invoke
expect(events).to eq([%i[git commit!], %i[package build!], %i[git tag!]])
end
it 'repeats the bump from the release version without consulting recorded completion' do
install
2.times do
Rake::Task['release:bump'].reenable
Rake::Task['release:bump'].invoke
end
expect(version).to have_received(:increment!).with(from: '2.0.0').twice
expect(objects.fetch(:git)).to have_received(:commit_next!).twice
end
it 'increments the configured next version part from the release version', :aggregate_failures do
install(next_version: :minor)
Rake::Task['release:bump'].invoke
expect(version).to have_received(:increment!).with(from: '2.0.0', part: :minor)
expect(objects.fetch(:git)).to have_received(:commit_next!).with(having_attributes(next_version: '2.0.1'))
end
it 'accepts next version parts as strings' do
install(next_version: 'major')
Rake::Task['release:bump'].invoke
expect(version).to have_received(:increment!).with(from: '2.0.0', part: :major)
end
it 'rejects unknown next version parts at construction', :aggregate_failures do
[:build, nil, 1, ''].each do |next_version|
expect { described_class.new(version: version, changelog: nil, next_version: next_version) }
.to raise_error(ArgumentError, 'next_version must be :major, :minor, or :patch')
end
end
it 'requires custom version objects to accept part: only for non-patch next versions', :aggregate_failures do
custom = Class.new do
def read = '1.2.3'
def set!(value) = value
def increment!(from:) = from
end.new
expect { described_class.new(version: custom, changelog: nil, next_version: :minor) }
.to raise_error(ArgumentError, "version object's increment! must accept part: to use next_version: :minor")
expect { described_class.new(version: custom, changelog: nil) }.not_to raise_error
end
it 'writes the next minor version through a reference-updating Ruby constant' do
Dir.mktmpdir do |directory|
path = File.join(directory, 'version.rb')
File.write(path, "VERSION = '2.0.0'\n")
constant = RubyGemRelease::Version::RubyConstant.new(path: path, constant: 'VERSION')
described_class.new(version: RubyGemRelease::Version::References.new(version: constant, references: {}), changelog: nil, **objects.except(:changelog), next_version: :minor).install_tasks
Rake::Task['release:bump'].invoke
expect(File.read(path)).to eq("VERSION = '2.1.0'\n")
end
end
it 'rejects an Actions checkpoint without a configured workflow' do
RubyGemRelease::Tasks.install
expect { Rake::Task['release:workflow:checkpoint'].invoke }.to raise_error(/must implement checkpoint!/)
expect(events).to be_empty
end
it 'uses custom validation instead of inferring the release decision' do
received = nil
install(validate: lambda { |ctx|
received = ctx.release
false
})
expect { Rake::Task['release:validate'].invoke }.to raise_error(ArgumentError, /validation failed/)
expect(received).to have_attributes(version: '1.2.3')
expect(objects.fetch(:changelog)).not_to have_received(:pending?)
end
it 'wires default objects in the existing release order without running during installation', :aggregate_failures do
install
expect(events).to be_empty
run_callbacks
expect(events).to eq([
:read, %i[changelog release!], %i[destination authenticate!], %i[git commit!], %i[package build!], %i[git tag!],
%i[destination publish!], %i[git push!], %i[hosting publish!],
:increment, %i[changelog prepare_next!], %i[git commit_next!], %i[git push!]
])
end
it 'runs configured success and failure callbacks with the appropriate release context', :aggregate_failures do
received = []
install = described_class.new(
version: version,
changelog: objects.fetch(:changelog),
success: ->(ctx) { received << [:success, ctx] },
failure: ->(failure) { received << [:failure, failure] }
)
install.install_tasks
Rake::Task['release:success'].invoke
Rake::Task['release:failure'].invoke
expect(received.map(&:first)).to eq(%i[success failure])
expect(received.first.last).to have_attributes(workflow: install, release: have_attributes(version: '2.0.0', gemspec_version: '1.2.3'))
expect(received.last.last).to have_attributes(phase: 'unknown', error: nil, context: have_attributes(workflow: install, release: have_attributes(version: '2.0.0', gemspec_version: '1.2.3')))
end
it 'makes configured components and the completed next development version available to success' do
received = nil
instance = described_class.new(version: version, changelog: objects.fetch(:changelog), success: ->(ctx) { received = ctx })
instance.install_tasks
run_callbacks
Rake::Task['release:success'].invoke
expect(received.release).to have_attributes(version: '2.0.0', next_version: '2.0.1')
expect(received.workflow).to equal(instance)
expect(received.workflow.version).to equal(version)
expect(received.workflow.git).to equal(objects.fetch(:git))
expect(received.workflow.destination).to equal(objects.fetch(:destination))
end
it 'does not record a completed next development iteration when pushing fails' do
received = nil
allow(objects.fetch(:git)).to receive(:push!).and_raise('push failed')
install(failure: ->(failure) { received = failure.context })
expect { Rake::Task['release:bump'].invoke }.to raise_error('push failed')
Rake::Task['release:failure'].invoke
expect(received.release.next_version).to be_nil
end
it 'preserves the initial context across version copies', :aggregate_failures do
received = []
allow(objects.fetch(:changelog)).to receive(:release!) { |release| received << release }
allow(objects.fetch(:changelog)).to receive(:prepare_next!) { |release| received << release }
install
run_callbacks
expect(received.map { |release| [release.version, release.gemspec_version, release.next_version, release.date] })
.to eq([['2.0.0', '1.2.3', nil, Date.new(2026, 11, 7)], ['2.0.0', '1.2.3', '2.0.1', Date.new(2026, 11, 7)]])
expect(received).to all(be_frozen)
expect(objects.fetch(:git)).to have_received(:commit!).with(an_instance_of(RubyGemRelease::Release))
expect(objects.fetch(:git)).to have_received(:commit_next!).with(received.last)
expect(objects.fetch(:hosting)).to have_received(:publish!).with(an_instance_of(RubyGemRelease::Release), package: objects.fetch(:package))
end
it 'sets a selected version before preparing the changelog and preserves the previous version', :aggregate_failures do
ENV['INPUT_VERSION'] = '3.0.0'
allow(version).to receive(:set!).with('3.0.0') { events << :set }
allow(version).to receive(:read).and_return('3.0.0')
install
Rake::Task['release:prepare'].invoke
expect(events).to eq([:set, %i[changelog release!]])
expect(objects.fetch(:changelog)).to have_received(:release!).with(have_attributes(version: '3.0.0', gemspec_version: '1.2.3'))
end
it 'sets a selected version even when changelog updates are disabled', :aggregate_failures do
ENV['INPUT_VERSION'] = '3.0.0'
allow(version).to receive(:set!).with('3.0.0')
described_class.new(version: version, changelog: nil).install_tasks
Rake::Task['release:prepare'].invoke
expect(version).to have_received(:set!).with('3.0.0')
expect(objects.fetch(:changelog)).not_to have_received(:release!)
end
it 'passes its execution provider to tasks and uses its selected version during preparation' do
provider = RubyGemRelease::ExecutionProvider.new(environment: ENV.to_h.merge('INPUT_VERSION' => '3.0.0', 'INPUT_GEMSPEC_PATH' => 'selected.gemspec'))
allow(version).to receive(:set!).with('3.0.0')
instance = described_class.new(version: version, changelog: nil, provider: provider)
instance.install_tasks
Rake::Task['release:prepare'].invoke
expect(version).to have_received(:set!).with('3.0.0')
expect(RubyGemRelease::Package::RubyGem).to have_received(:new).with(gemspec: 'selected.gemspec', directory: nil)
expect(instance.provider).to equal(provider)
end
it 'rejects invalid selected versions before invoking the setter or changelog', :aggregate_failures do
ENV['INPUT_VERSION'] = '03.0.0'
allow(version).to receive(:set!)
install
expect { Rake::Task['release:prepare'].invoke }.to raise_error(ArgumentError, /invalid version/)
expect(version).not_to have_received(:set!)
expect(events).to be_empty
end
it 'requires custom version objects to implement read, set!, and increment! at construction' do
custom = Struct.new(:read, :increment!).new('1.2.3')
expect { described_class.new(version: custom, changelog: objects.fetch(:changelog)) }.to raise_error(ArgumentError, 'version object must implement set!')
end
it 'uses supplied publication objects instead of constructing defaults', :aggregate_failures do
install(**objects.except(:changelog))
Rake::Task['release:publish'].invoke
expect(RubyGemRelease::Package::RubyGem).not_to have_received(:new)
expect(RubyGemRelease::Destination::RubyGems).not_to have_received(:new)
expect(RubyGemRelease::SourceControl::Git).not_to have_received(:new)
expect(RubyGemRelease::Hosting::GitHubRelease).not_to have_received(:new)
expect(objects.fetch(:hosting)).to have_received(:publish!).with(an_instance_of(RubyGemRelease::Release), package: objects.fetch(:package))
end
it 'passes the configured package to capture as well as publication' do
environment = instance_double(RubyGemRelease::Workflow::Environment, capture!: nil)
allow(RubyGemRelease::Workflow::Environment).to receive(:new).and_return(environment)
install(**objects.except(:changelog))
Rake::Task['release:workflow:capture'].invoke
expect(environment).to have_received(:capture!).with(package: objects.fetch(:package))
expect(RubyGemRelease::Package::RubyGem).not_to have_received(:new)
end
it 'disables hosted releases without skipping package publication', :aggregate_failures do
install(hosting: nil)
Rake::Task['release:publish'].invoke
expect(events).to eq([%i[destination authenticate!], %i[git commit!], %i[package build!], %i[git tag!], %i[destination publish!], %i[git push!]])
expect(RubyGemRelease::Hosting::GitHubRelease).not_to have_received(:new)
end
it 'disables changelog updates but still increments and commits the next development iteration', :aggregate_failures do
described_class.new(version: version, changelog: nil).install_tasks
run_callbacks
expect(events).to include(:increment, %i[git commit_next!])
expect(events).not_to include(:read, %i[changelog release!], %i[changelog prepare_next!])
end
it 'stops publication immediately after a build failure', :aggregate_failures do
allow(objects.fetch(:package)).to receive(:build!).and_raise('build failed')
install
expect { Rake::Task['release:publish'].invoke }.to raise_error('build failed')
expect(events).to eq([%i[destination authenticate!], %i[git commit!]])
end
it 'stops before pushing or creating a hosted release when the registry destination fails' do
allow(objects.fetch(:destination)).to receive(:publish!).and_raise('registry unavailable')
install
expect { Rake::Task['release:publish'].invoke }.to raise_error('registry unavailable')
expect(events).to eq([%i[destination authenticate!], %i[git commit!], %i[package build!], %i[git tag!]])
expect(objects.fetch(:destination)).to have_received(:publish!).with(an_instance_of(RubyGemRelease::Release), package: objects.fetch(:package))
end
it 'stops before publication operations when destination authentication fails' do
allow(objects.fetch(:destination)).to receive(:authenticate!).and_raise('authentication failed')
install
expect { Rake::Task['release:publish'].invoke }.to raise_error('authentication failed')
expect(events).to be_empty
end
it 'stops before committing when next development iteration changelog preparation fails', :aggregate_failures do
allow(objects.fetch(:changelog)).to receive(:prepare_next!).and_raise('changelog failed')
install
expect { Rake::Task['release:bump'].invoke }.to raise_error('changelog failed')
expect(events).to eq([:increment])
end
it 'runs additive preparation hooks in order inside trusted staging without replacing the changelog' do
trusted = false
allow(objects.fetch(:git)).to receive(:stage_changes!) do |&block|
trusted = true
block.call
trusted = false
end
workflow = described_class.new(version: version, changelog: objects.fetch(:changelog))
%i[before after].each do |timing|
2.times do |index|
workflow.public_send(timing, :prepare_release) do |ctx|
expect(trusted).to be(true)
expect(ctx).to have_attributes(workflow: workflow, stage: :prepare_release, hook: timing, hook_index: index + 1)
events << [timing, index]
end
end
end
workflow.install_tasks
Rake::Task['release:prepare'].invoke
expect(events).to eq([[:before, 0], [:before, 1], :read, %i[changelog release!], [:after, 0], [:after, 1]])
end
it 'retains built-in validation and suppresses after hooks when it fails' do
workflow = described_class.new(version: version, changelog: objects.fetch(:changelog))
workflow.before(:validate) { events << :before_validate }
workflow.after(:validate) { events << :after_validate }
allow(objects.fetch(:changelog)).to receive(:pending?).and_return(false)
workflow.install_tasks
expect { Rake::Task['release:validate'].invoke }.to raise_error(ArgumentError, /Nothing to release/)
expect(events).to eq([:before_validate])
end
it 'does not run validation after hooks when a replacement validator returns false' do
workflow = described_class.new(version: version, changelog: nil, validate: ->(_) { false })
workflow.after(:validate) { events << :after_validate }
workflow.install_tasks
expect { Rake::Task['release:validate'].invoke }.to raise_error(ArgumentError, /callback returned false/)
expect(events).to be_empty
end
it 'supplies the calculated next version before the development commit and distinguishes both pushes' do
workflow = described_class.new(version: version, changelog: objects.fetch(:changelog))
%i[prepare_next push_release push_next].each do |stage|
workflow.after(stage) { |ctx| events << [stage, ctx.release.next_version] }
end
workflow.install_tasks
run_callbacks
expect(events.last(8)).to eq([
[:push_release, nil], %i[hosting publish!], :increment, %i[changelog prepare_next!],
[:prepare_next, '2.0.1'], %i[git commit_next!], %i[git push!], [:push_next, '2.0.1']
])
end
it 'preserves result callbacks between ordered hooks and exposes the original failure' do
workflow = described_class.new(version: version, changelog: nil,
success: ->(_) { events << :success_callback }, failure: ->(_) { events << :failure_callback })
%i[success failure].each do |stage|
workflow.before(stage) do |ctx|
expect(ctx.failure).to be_a(RubyGemRelease::ReleaseFailure) if stage == :failure
events << :"before_#{stage}"
end
workflow.after(stage) { events << :"after_#{stage}" }
end
workflow.install_tasks
Rake::Task['release:success'].invoke
Rake::Task['release:failure'].invoke
expect(events).to eq(%i[before_success success_callback after_success before_failure failure_callback after_failure])
end
it 'captures the exact failing stage and hook without changing the exception class' do
Dir.mktmpdir do |directory|
ENV.update('RELEASE_DATA_DIR' => directory, 'RELEASE_FAILED_STEP_ID' => 'release:prepare')
received = nil
workflow = described_class.new(version: version, changelog: nil, failure: ->(failure) { received = failure })
workflow.before(:prepare_release) { events << :first }
workflow.before(:prepare_release) { raise ArgumentError, 'project notes invalid' }
workflow.after(:prepare_release) { events << :after }
workflow.install_tasks
expect { Rake::Task['release:prepare'].invoke }.to raise_error(ArgumentError, 'project notes invalid')
Rake::Task['release:failure'].invoke
expect(received.error).to have_attributes(original_class: 'ArgumentError', stage: :prepare_release, hook: :before, hook_index: 2)
expect(events).to eq([:first])
end
end
it 'reports built-in operation failures with their lifecycle stage' do
Dir.mktmpdir do |directory|
ENV.update('RELEASE_DATA_DIR' => directory, 'RELEASE_FAILED_STEP_ID' => 'release:publish')
received = nil
allow(objects.fetch(:package)).to receive(:build!).and_raise('build failed')
install(failure: ->(failure) { received = failure })
expect { Rake::Task['release:publish'].invoke }.to raise_error('build failed')
Rake::Task['release:failure'].invoke
expect(received.error).to have_attributes(stage: :build_package, hook: nil, hook_index: nil)
end
end
it 'rejects unknown stages and hooks without a block at registration' do
workflow = described_class.new(version: version, changelog: nil)
expect { workflow.before(:push) { nil } }.to raise_error(ArgumentError, /unknown lifecycle stage/)
expect { workflow.after(:validate) }.to raise_error(ArgumentError, /requires a block/)
end
it 'runs checkpoint and publication preparation hooks in both tasks' do
workflow = described_class.new(version: version, changelog: nil, hosting: nil)
%i[checkpoint commit_release build_package tag_release publish_registry publish_hosted_release].each do |stage|
workflow.before(stage) { events << stage }
end
workflow.install_tasks
Rake::Task['release:workflow:checkpoint'].invoke
2.times do
Rake::Task['release:publish'].reenable
Rake::Task['release:publish'].invoke
end
expect(events.count(:checkpoint)).to eq(1)
expect(events.count(:build_package)).to eq(3)
expect(events.count(:commit_release)).to eq(3)
expect(events.count(:tag_release)).to eq(3)
expect(events.count(:publish_registry)).to eq(2)
expect(events).not_to include(:publish_hosted_release)
end
it 'skips authentication hooks when the destination already verifies the exact publication' do
allow(objects.fetch(:package)).to receive(:built?).and_return(true)
allow(objects.fetch(:destination)).to receive(:published?).and_return(true)
workflow = described_class.new(version: version, changelog: nil)
workflow.before(:authenticate) { events << :authenticate_hook }
workflow.install_tasks
Rake::Task['release:publish'].invoke
expect(events).not_to include(:authenticate_hook, %i[destination authenticate!])
end
it 'does not run subsequent hooks after an after hook fails' do
workflow = described_class.new(version: version, changelog: nil)
workflow.after(:prepare_release) { raise 'readme update failed' }
workflow.after(:prepare_release) { events << :unreachable }
workflow.install_tasks
expect { Rake::Task['release:prepare'].invoke }.to raise_error('readme update failed')
expect(events).to be_empty
end
it 'does not overwrite the original captured error when a failure hook fails' do
Dir.mktmpdir do |directory|
ENV.update('RELEASE_DATA_DIR' => directory, 'RELEASE_FAILED_STEP_ID' => 'release:validate')
workflow = described_class.new(version: version, changelog: nil, validate: ->(_) { raise 'original validation error' })
workflow.before(:failure) { raise 'notification failed' }
workflow.after(:failure) { events << :unreachable }
workflow.install_tasks
expect { Rake::Task['release:validate'].invoke }.to raise_error('original validation error')
expect { Rake::Task['release:failure'].invoke }.to raise_error('notification failed')
original = RubyGemRelease::Workflow::Failure.error_for('release:validate', provider: workflow.provider)
expect(original).to have_attributes(message: 'original validation error', stage: :validate)
expect(events).to be_empty
end
end
it 'retains concurrency checks before registry publication' do
allow(objects.fetch(:git)).to receive(:tag!).and_raise('Default branch advanced; start a new release')
install
expect { Rake::Task['release:publish'].invoke }.to raise_error(/Default branch advanced/)
expect(objects.fetch(:destination)).not_to have_received(:publish!)
expect(objects.fetch(:package)).to have_received(:build!)
end
it 'runs result hooks without requiring replacement result callbacks' do
workflow = described_class.new(version: version, changelog: nil)
workflow.after(:success) { events << :success_hook }
workflow.after(:failure) { events << :failure_hook }
workflow.install_tasks
Rake::Task['release:success'].invoke
Rake::Task['release:failure'].invoke
expect(events).to eq(%i[success_hook failure_hook])
end
end