summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_commands_push_command.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-25 07:30:41 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-25 07:30:41 +0000
commite276482efc1c274ba9cfe17f5e6fbe02819a15bb (patch)
treebd7593e76ccb8374388f6ec5f8f6f639e696a7fb /test/rubygems/test_gem_commands_push_command.rb
parentbe26224be568166b5db530cd377bf71d78e985d8 (diff)
* lib/rubygems/config_file.rb: Lazily load .gem/credentials to only
check permissions when necessary. RubyGems bug #465 * test/rubygems/test_gem_config_file.rb: Test for the above. * test/rubygems/test_gem_commands_push_command.rb: Remove duplicated test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39491 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_commands_push_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb43
1 files changed, 25 insertions, 18 deletions
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index 5245e864d2..73fd7bf540 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -18,7 +18,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
"ed244fbf2b1a52e012da8616c512fa47f9aa5250"
@spec, @path = util_gem "freewill", "1.0.0"
- @host = Gem.host
+ @host = 'https://rubygems.example'
@api_key = Gem.configuration.rubygems_api_key
@fetcher = Gem::FakeFetcher.new
@@ -61,6 +61,27 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_match @response, @ui.output
end
+ def test_execute_host
+ host = 'https://other.example'
+
+ open 'example', 'w' do |io| io.write 'hello' end
+
+ @response = "Successfully registered gem: freewill (1.0.0)"
+ @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["#{Gem.host}/api/v1/gems"] =
+ ['fail', 500, 'Internal Server Error']
+
+ @cmd.options[:host] = host
+ @cmd.options[:args] = %w[example]
+
+ @cmd.execute
+
+ assert_equal Net::HTTP::Post, @fetcher.last_request.class
+ assert_equal 'hello', @fetcher.last_request.body
+ assert_equal "application/octet-stream",
+ @fetcher.last_request["Content-Type"]
+ end
+
def test_sending_when_default_host_disabled
Gem.configuration.disable_default_gem_server = true
response = "You must specify a gem server"
@@ -110,29 +131,13 @@ class TestGemCommandsPushCommand < Gem::TestCase
send_battery
end
- def test_sending_gem_default
+ def test_sending_gem
@response = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
send_battery
end
- def test_sending_gem_host
- @response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
- @cmd.options['host'] = "#{Gem.host}"
-
- send_battery
- end
-
- def test_sending_gem_ENV
- @response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
- ENV["RUBYGEMS_HOST"] = "#{Gem.host}"
-
- send_battery
- end
-
def test_raises_error_with_no_arguments
def @cmd.sign_in(*); end
assert_raises Gem::CommandLineError do
@@ -143,6 +148,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_denied
response = "You don't have permission to push to this gem"
@fetcher.data["#{@host}/api/v1/gems"] = [response, 403, 'Forbidden']
+ @cmd.instance_variable_set :@host, @host
assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@@ -162,6 +168,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
Gem.configuration.load_api_keys
@cmd.handle_options %w(-k other)
+ @cmd.instance_variable_set :@host, @host
@cmd.send_gem(@path)
assert_equal Gem.configuration.api_keys[:other],