diff options
Diffstat (limited to 'test/rubygems/test_gem_commands_signin_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_signin_command.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb index 21d19fffc9..f8262466b1 100644 --- a/test/rubygems/test_gem_commands_signin_command.rb +++ b/test/rubygems/test_gem_commands_signin_command.rb @@ -73,14 +73,38 @@ class TestGemCommandsSigninCommand < Gem::TestCase assert_equal api_key, credentials[:rubygems_api_key] end + def test_excute_with_key_name_and_scope + email = 'you@example.com' + password = 'secret' + api_key = '1234' + fetcher = Gem::RemoteFetcher.fetcher + + key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\n" + util_capture(key_name_ui, nil, api_key, fetcher) { @cmd.execute } + + user = ENV["USER"] || ENV["USERNAME"] + + assert_match "API Key name [#{Socket.gethostname}-#{user}", key_name_ui.output + assert_match "index_rubygems [y/N]", key_name_ui.output + assert_match "push_rubygem [y/N]", key_name_ui.output + assert_match "yank_rubygem [y/N]", key_name_ui.output + assert_match "add_owner [y/N]", key_name_ui.output + assert_match "remove_owner [y/N]", key_name_ui.output + assert_match "access_webhooks [y/N]", key_name_ui.output + assert_match "show_dashboard [y/N]", key_name_ui.output + assert_equal "name=test-key&push_rubygem=true", fetcher.last_request.body + + credentials = YAML.load_file Gem.configuration.credentials_path + assert_equal api_key, credentials[:rubygems_api_key] + end + # Utility method to capture IO/UI within the block passed - def util_capture(ui_stub = nil, host = nil, api_key = nil) + def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new) api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' response = [api_key, 200, 'OK'] email = 'you@example.com' password = 'secret' - fetcher = Gem::FakeFetcher.new # Set the expected response for the Web-API supplied ENV['RUBYGEMS_HOST'] = host || Gem::DEFAULT_HOST @@ -88,7 +112,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase fetcher.data[data_key] = response Gem::RemoteFetcher.fetcher = fetcher - sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n") + sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n") use_ui sign_in_ui do yield |