Skip to content

Commit 1b190b3

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] TermError should inherit from SystemExit
The `gem owner` command rescues standard errors, but does not rescue SystemExit errors. If TermError is a standard error, not a system exit, tests don't behave like realworld for this command. ruby/rubygems@cf7d500f4d
1 parent 7fba517 commit 1b190b3

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

test/rubygems/mock_gem_ui.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize(question)
1616
end
1717
end
1818

19-
class TermError < RuntimeError
19+
class TermError < SystemExit
2020
attr_reader :exit_code
2121

2222
def initialize(exit_code)

test/rubygems/test_gem_commands_owner_command.rb

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ def test_add_owners_denied
176176
response = "You don't have permission to push to this gem"
177177
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
178178

179-
use_ui @stub_ui do
180-
@cmd.add_owners("freewill", ["[email protected]"])
179+
assert_raise Gem::MockGemUi::TermError do
180+
use_ui @stub_ui do
181+
@cmd.add_owners("freewill", ["[email protected]"])
182+
end
181183
end
182184

183185
assert_match response, @stub_ui.output
@@ -196,8 +198,10 @@ def test_add_owners_permanent_redirect
196198
headers: { "location" => redirected_uri }
197199
)
198200

199-
use_ui @stub_ui do
200-
@cmd.add_owners("freewill", ["[email protected]"])
201+
assert_raise Gem::MockGemUi::TermError do
202+
use_ui @stub_ui do
203+
@cmd.add_owners("freewill", ["[email protected]"])
204+
end
201205
end
202206

203207
response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
@@ -255,8 +259,10 @@ def test_remove_owners_denied
255259
response = "You don't have permission to push to this gem"
256260
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
257261

258-
use_ui @stub_ui do
259-
@cmd.remove_owners("freewill", ["[email protected]"])
262+
assert_raise Gem::MockGemUi::TermError do
263+
use_ui @stub_ui do
264+
@cmd.remove_owners("freewill", ["[email protected]"])
265+
end
260266
end
261267

262268
assert_match response, @stub_ui.output
@@ -274,8 +280,10 @@ def test_remove_owners_permanent_redirect
274280
headers: { "location" => redirected_uri }
275281
)
276282

277-
use_ui @stub_ui do
278-
@cmd.remove_owners("freewill", ["[email protected]"])
283+
assert_raise Gem::MockGemUi::TermError do
284+
use_ui @stub_ui do
285+
@cmd.remove_owners("freewill", ["[email protected]"])
286+
end
279287
end
280288

281289
response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
@@ -291,8 +299,10 @@ def test_remove_owners_permanent_redirect
291299
headers: { "location" => redirected_uri }
292300
)
293301

294-
use_ui @stub_ui do
295-
@cmd.add_owners("freewill", ["[email protected]"])
302+
assert_raise Gem::MockGemUi::TermError do
303+
use_ui @stub_ui do
304+
@cmd.add_owners("freewill", ["[email protected]"])
305+
end
296306
end
297307

298308
response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
@@ -317,8 +327,10 @@ def test_remove_owners_missing
317327
response = "Owner could not be found."
318328
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 404, msg: "Not Found")
319329

320-
use_ui @stub_ui do
321-
@cmd.remove_owners("freewill", ["missing@example"])
330+
assert_raise Gem::MockGemUi::TermError do
331+
use_ui @stub_ui do
332+
@cmd.remove_owners("freewill", ["missing@example"])
333+
end
322334
end
323335

324336
assert_equal "Removing missing@example: #{response}\n", @stub_ui.output
@@ -346,8 +358,11 @@ def test_otp_verified_failure
346358
HTTPResponseFactory.create(body: "You don't have any security devices", code: 422, msg: "Unprocessable Entity")
347359

348360
@otp_ui = Gem::MockGemUi.new "111111\n"
349-
use_ui @otp_ui do
350-
@cmd.add_owners("freewill", ["[email protected]"])
361+
362+
assert_raise Gem::MockGemUi::TermError do
363+
use_ui @otp_ui do
364+
@cmd.add_owners("freewill", ["[email protected]"])
365+
end
351366
end
352367

353368
assert_match response, @otp_ui.output
@@ -389,8 +404,10 @@ def test_with_webauthn_enabled_failure
389404

390405
TCPServer.stub(:new, server) do
391406
Gem::GemcutterUtilities::WebauthnListener.stub(:listener_thread, Thread.new { Thread.current[:error] = error }) do
392-
use_ui @stub_ui do
393-
@cmd.add_owners("freewill", ["[email protected]"])
407+
assert_raise Gem::MockGemUi::TermError do
408+
use_ui @stub_ui do
409+
@cmd.add_owners("freewill", ["[email protected]"])
410+
end
394411
end
395412
end
396413
end
@@ -438,8 +455,10 @@ def test_with_webauthn_enabled_failure_with_polling
438455
@stub_fetcher.respond_with_webauthn_polling_failure
439456

440457
TCPServer.stub(:new, server) do
441-
use_ui @stub_ui do
442-
@cmd.add_owners("freewill", ["[email protected]"])
458+
assert_raise Gem::MockGemUi::TermError do
459+
use_ui @stub_ui do
460+
@cmd.add_owners("freewill", ["[email protected]"])
461+
end
443462
end
444463
end
445464

0 commit comments

Comments
 (0)