diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
commit | 9694bb8cac12969300692dac5a1cf7aa4e3a46cd (patch) | |
tree | c3cb423d701f7049ba9382de052e2a937cd1302d /test/rubygems/test_gem_commands_yank_command.rb | |
parent | 3f606b7063fc7a8b191556365ad343a314719a8d (diff) | |
download | ruby-9694bb8cac12969300692dac5a1cf7aa4e3a46cd.tar.gz |
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto.
* common.mk (prelude): Updated for RubyGems 2.0 source rearrangement.
* tool/change_maker.rb: Allow invalid UTF-8 characters in source
files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_commands_yank_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_yank_command.rb | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb new file mode 100644 index 0000000000..e627452243 --- /dev/null +++ b/test/rubygems/test_gem_commands_yank_command.rb @@ -0,0 +1,97 @@ +require 'rubygems/test_case' +require 'rubygems/commands/yank_command' + +class TestGemCommandsYankCommand < Gem::TestCase + def setup + super + + @cmd = Gem::Commands::YankCommand.new + @cmd.host = 'http://example' + + @fetcher = Gem::RemoteFetcher.fetcher + + Gem.configuration.rubygems_api_key = 'key' + Gem.configuration.api_keys[:KEY] = 'other' + end + + def test_handle_options + @cmd.handle_options %w[a --version 1.0 --platform x86-darwin -k KEY] + + assert_equal %w[a], @cmd.options[:args] + assert_equal 'KEY', @cmd.options[:key] + assert_nil @cmd.options[:platform] + assert_equal req('= 1.0'), @cmd.options[:version] + end + + def test_handle_options_missing_argument + %w[-v --version -p --platform].each do |option| + assert_raises OptionParser::MissingArgument do + @cmd.handle_options %W[a #{option}] + end + end + end + + def test_execute + yank_uri = 'http://example/api/v1/gems/yank' + @fetcher.data[yank_uri] = ['Successfully yanked', 200, 'OK'] + + @cmd.options[:args] = %w[a] + @cmd.options[:added_platform] = true + @cmd.options[:version] = req('= 1.0') + + use_ui @ui do + @cmd.execute + end + + assert_match %r%Yanking gem from http://example%, @ui.output + assert_match %r%Successfully yanked%, @ui.output + + platform = Gem.platforms[1] + body = @fetcher.last_request.body.split('&').sort + assert_equal %W[gem_name=a platform=#{platform} version=1.0], body + + assert_equal 'key', @fetcher.last_request['Authorization'] + + assert_equal [yank_uri], @fetcher.paths + end + + def test_execute_key + yank_uri = 'http://example/api/v1/gems/yank' + @fetcher.data[yank_uri] = ['Successfully yanked', 200, 'OK'] + + @cmd.options[:args] = %w[a] + @cmd.options[:version] = req('= 1.0') + @cmd.options[:key] = 'KEY' + + use_ui @ui do + @cmd.execute + end + + body = @fetcher.last_request.body.split('&').sort + assert_equal %w[gem_name=a version=1.0], body + assert_equal 'other', @fetcher.last_request['Authorization'] + end + + def test_execute_undo + unyank_uri = 'http://example/api/v1/gems/unyank' + @fetcher.data[unyank_uri] = ['Successfully unyanked', 200, 'OK'] + + @cmd.options[:args] = %w[a] + @cmd.options[:version] = req('= 1.0') + @cmd.options[:undo] = true + + use_ui @ui do + @cmd.execute + end + + assert_match %r%Unyanking gem from http://example%, @ui.output + assert_match %r%Successfully unyanked%, @ui.output + + body = @fetcher.last_request.body.split('&').sort + assert_equal %w[gem_name=a version=1.0], body + + assert_equal [unyank_uri], @fetcher.paths + end + +end + |