summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2024-10-31 19:47:01 +0100
committergit <[email protected]>2024-11-04 10:04:58 +0000
commit1b190b342b2f642cbba12cf6551df2bec7432d71 (patch)
treecb6df55ec236ec838db32bf905a785b22e9869ee
parent7fba517d5028eb810c07d4beca601f1382d66708 (diff)
[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. https://github.com/rubygems/rubygems/commit/cf7d500f4d
-rw-r--r--test/rubygems/mock_gem_ui.rb2
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb55
2 files changed, 38 insertions, 19 deletions
diff --git a/test/rubygems/mock_gem_ui.rb b/test/rubygems/mock_gem_ui.rb
index 1ece78fde7..218d4b6965 100644
--- a/test/rubygems/mock_gem_ui.rb
+++ b/test/rubygems/mock_gem_ui.rb
@@ -16,7 +16,7 @@ class Gem::MockGemUi < Gem::StreamUI
end
end
- class TermError < RuntimeError
+ class TermError < SystemExit
attr_reader :exit_code
def initialize(exit_code)
diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb
index eddd8afaf5..9e6c004aab 100644
--- a/test/rubygems/test_gem_commands_owner_command.rb
+++ b/test/rubygems/test_gem_commands_owner_command.rb
@@ -176,8 +176,10 @@ EOF
response = "You don't have permission to push to this gem"
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
- use_ui @stub_ui do
- @cmd.add_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["[email protected]"])
+ end
end
assert_match response, @stub_ui.output
@@ -196,8 +198,10 @@ EOF
headers: { "location" => redirected_uri }
)
- use_ui @stub_ui do
- @cmd.add_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["[email protected]"])
+ end
end
response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
@@ -255,8 +259,10 @@ EOF
response = "You don't have permission to push to this gem"
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
- use_ui @stub_ui do
- @cmd.remove_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.remove_owners("freewill", ["[email protected]"])
+ end
end
assert_match response, @stub_ui.output
@@ -274,8 +280,10 @@ EOF
headers: { "location" => redirected_uri }
)
- use_ui @stub_ui do
- @cmd.remove_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.remove_owners("freewill", ["[email protected]"])
+ end
end
response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
@@ -291,8 +299,10 @@ EOF
headers: { "location" => redirected_uri }
)
- use_ui @stub_ui do
- @cmd.add_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["[email protected]"])
+ end
end
response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
@@ -317,8 +327,10 @@ EOF
response = "Owner could not be found."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 404, msg: "Not Found")
- use_ui @stub_ui do
- @cmd.remove_owners("freewill", ["missing@example"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.remove_owners("freewill", ["missing@example"])
+ end
end
assert_equal "Removing missing@example: #{response}\n", @stub_ui.output
@@ -346,8 +358,11 @@ EOF
HTTPResponseFactory.create(body: "You don't have any security devices", code: 422, msg: "Unprocessable Entity")
@otp_ui = Gem::MockGemUi.new "111111\n"
- use_ui @otp_ui do
- @cmd.add_owners("freewill", ["[email protected]"])
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @otp_ui do
+ @cmd.add_owners("freewill", ["[email protected]"])
+ end
end
assert_match response, @otp_ui.output
@@ -389,8 +404,10 @@ EOF
TCPServer.stub(:new, server) do
Gem::GemcutterUtilities::WebauthnListener.stub(:listener_thread, Thread.new { Thread.current[:error] = error }) do
- use_ui @stub_ui do
- @cmd.add_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["[email protected]"])
+ end
end
end
end
@@ -438,8 +455,10 @@ EOF
@stub_fetcher.respond_with_webauthn_polling_failure
TCPServer.stub(:new, server) do
- use_ui @stub_ui do
- @cmd.add_owners("freewill", ["[email protected]"])
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["[email protected]"])
+ end
end
end