libgems 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5811 -0
- data/History.txt +887 -0
- data/LICENSE.txt +51 -0
- data/README.md +87 -0
- data/Rakefile +113 -0
- data/lib/gauntlet_libgems.rb +50 -0
- data/lib/libgems.rb +1246 -0
- data/lib/libgems/builder.rb +102 -0
- data/lib/libgems/command.rb +534 -0
- data/lib/libgems/command_manager.rb +182 -0
- data/lib/libgems/commands/build_command.rb +53 -0
- data/lib/libgems/commands/cert_command.rb +86 -0
- data/lib/libgems/commands/check_command.rb +80 -0
- data/lib/libgems/commands/cleanup_command.rb +106 -0
- data/lib/libgems/commands/contents_command.rb +98 -0
- data/lib/libgems/commands/dependency_command.rb +195 -0
- data/lib/libgems/commands/environment_command.rb +133 -0
- data/lib/libgems/commands/fetch_command.rb +67 -0
- data/lib/libgems/commands/generate_index_command.rb +133 -0
- data/lib/libgems/commands/help_command.rb +172 -0
- data/lib/libgems/commands/install_command.rb +178 -0
- data/lib/libgems/commands/list_command.rb +35 -0
- data/lib/libgems/commands/lock_command.rb +110 -0
- data/lib/libgems/commands/mirror_command.rb +111 -0
- data/lib/libgems/commands/outdated_command.rb +33 -0
- data/lib/libgems/commands/owner_command.rb +75 -0
- data/lib/libgems/commands/pristine_command.rb +93 -0
- data/lib/libgems/commands/push_command.rb +56 -0
- data/lib/libgems/commands/query_command.rb +280 -0
- data/lib/libgems/commands/rdoc_command.rb +91 -0
- data/lib/libgems/commands/search_command.rb +31 -0
- data/lib/libgems/commands/server_command.rb +86 -0
- data/lib/libgems/commands/sources_command.rb +157 -0
- data/lib/libgems/commands/specification_command.rb +125 -0
- data/lib/libgems/commands/stale_command.rb +27 -0
- data/lib/libgems/commands/uninstall_command.rb +83 -0
- data/lib/libgems/commands/unpack_command.rb +121 -0
- data/lib/libgems/commands/update_command.rb +160 -0
- data/lib/libgems/commands/which_command.rb +86 -0
- data/lib/libgems/config_file.rb +345 -0
- data/lib/libgems/custom_require.rb +44 -0
- data/lib/libgems/defaults.rb +101 -0
- data/lib/libgems/dependency.rb +227 -0
- data/lib/libgems/dependency_installer.rb +286 -0
- data/lib/libgems/dependency_list.rb +208 -0
- data/lib/libgems/doc_manager.rb +242 -0
- data/lib/libgems/errors.rb +35 -0
- data/lib/libgems/exceptions.rb +91 -0
- data/lib/libgems/ext.rb +18 -0
- data/lib/libgems/ext/builder.rb +56 -0
- data/lib/libgems/ext/configure_builder.rb +25 -0
- data/lib/libgems/ext/ext_conf_builder.rb +24 -0
- data/lib/libgems/ext/rake_builder.rb +39 -0
- data/lib/libgems/format.rb +81 -0
- data/lib/libgems/gem_openssl.rb +92 -0
- data/lib/libgems/gem_path_searcher.rb +100 -0
- data/lib/libgems/gem_runner.rb +79 -0
- data/lib/libgems/gemcutter_utilities.rb +49 -0
- data/lib/libgems/indexer.rb +720 -0
- data/lib/libgems/install_update_options.rb +125 -0
- data/lib/libgems/installer.rb +604 -0
- data/lib/libgems/local_remote_options.rb +135 -0
- data/lib/libgems/old_format.rb +153 -0
- data/lib/libgems/package.rb +97 -0
- data/lib/libgems/package/f_sync_dir.rb +23 -0
- data/lib/libgems/package/tar_header.rb +266 -0
- data/lib/libgems/package/tar_input.rb +222 -0
- data/lib/libgems/package/tar_output.rb +144 -0
- data/lib/libgems/package/tar_reader.rb +106 -0
- data/lib/libgems/package/tar_reader/entry.rb +141 -0
- data/lib/libgems/package/tar_writer.rb +241 -0
- data/lib/libgems/package_task.rb +126 -0
- data/lib/libgems/platform.rb +183 -0
- data/lib/libgems/remote_fetcher.rb +414 -0
- data/lib/libgems/require_paths_builder.rb +18 -0
- data/lib/libgems/requirement.rb +153 -0
- data/lib/libgems/security.rb +814 -0
- data/lib/libgems/server.rb +872 -0
- data/lib/libgems/source_index.rb +597 -0
- data/lib/libgems/source_info_cache.rb +395 -0
- data/lib/libgems/source_info_cache_entry.rb +56 -0
- data/lib/libgems/spec_fetcher.rb +337 -0
- data/lib/libgems/specification.rb +1487 -0
- data/lib/libgems/test_utilities.rb +147 -0
- data/lib/libgems/text.rb +65 -0
- data/lib/libgems/uninstaller.rb +278 -0
- data/lib/libgems/user_interaction.rb +527 -0
- data/lib/libgems/validator.rb +240 -0
- data/lib/libgems/version.rb +316 -0
- data/lib/libgems/version_option.rb +65 -0
- data/lib/rbconfig/datadir.rb +20 -0
- data/test/bogussources.rb +8 -0
- data/test/data/gem-private_key.pem +27 -0
- data/test/data/gem-public_cert.pem +20 -0
- data/test/fake_certlib/openssl.rb +7 -0
- data/test/foo/discover.rb +0 -0
- data/test/gem_installer_test_case.rb +97 -0
- data/test/gem_package_tar_test_case.rb +132 -0
- data/test/gemutilities.rb +605 -0
- data/test/insure_session.rb +43 -0
- data/test/mockgemui.rb +56 -0
- data/test/plugin/exception/libgems_plugin.rb +2 -0
- data/test/plugin/load/libgems_plugin.rb +1 -0
- data/test/plugin/standarderror/libgems_plugin.rb +2 -0
- data/test/private_key.pem +27 -0
- data/test/public_cert.pem +20 -0
- data/test/rubygems_plugin.rb +21 -0
- data/test/simple_gem.rb +66 -0
- data/test/test_config.rb +12 -0
- data/test/test_gem.rb +780 -0
- data/test/test_gem_builder.rb +27 -0
- data/test/test_gem_command.rb +178 -0
- data/test/test_gem_command_manager.rb +207 -0
- data/test/test_gem_commands_build_command.rb +74 -0
- data/test/test_gem_commands_cert_command.rb +124 -0
- data/test/test_gem_commands_check_command.rb +18 -0
- data/test/test_gem_commands_contents_command.rb +156 -0
- data/test/test_gem_commands_dependency_command.rb +216 -0
- data/test/test_gem_commands_environment_command.rb +144 -0
- data/test/test_gem_commands_fetch_command.rb +76 -0
- data/test/test_gem_commands_generate_index_command.rb +135 -0
- data/test/test_gem_commands_install_command.rb +315 -0
- data/test/test_gem_commands_list_command.rb +36 -0
- data/test/test_gem_commands_lock_command.rb +68 -0
- data/test/test_gem_commands_mirror_command.rb +60 -0
- data/test/test_gem_commands_outdated_command.rb +40 -0
- data/test/test_gem_commands_owner_command.rb +105 -0
- data/test/test_gem_commands_pristine_command.rb +108 -0
- data/test/test_gem_commands_push_command.rb +81 -0
- data/test/test_gem_commands_query_command.rb +426 -0
- data/test/test_gem_commands_server_command.rb +59 -0
- data/test/test_gem_commands_sources_command.rb +209 -0
- data/test/test_gem_commands_specification_command.rb +139 -0
- data/test/test_gem_commands_stale_command.rb +38 -0
- data/test/test_gem_commands_uninstall_command.rb +83 -0
- data/test/test_gem_commands_unpack_command.rb +199 -0
- data/test/test_gem_commands_update_command.rb +207 -0
- data/test/test_gem_commands_which_command.rb +66 -0
- data/test/test_gem_config_file.rb +287 -0
- data/test/test_gem_dependency.rb +149 -0
- data/test/test_gem_dependency_installer.rb +661 -0
- data/test/test_gem_dependency_list.rb +230 -0
- data/test/test_gem_doc_manager.rb +31 -0
- data/test/test_gem_ext_configure_builder.rb +84 -0
- data/test/test_gem_ext_ext_conf_builder.rb +173 -0
- data/test/test_gem_ext_rake_builder.rb +81 -0
- data/test/test_gem_format.rb +70 -0
- data/test/test_gem_gem_path_searcher.rb +78 -0
- data/test/test_gem_gem_runner.rb +45 -0
- data/test/test_gem_gemcutter_utilities.rb +103 -0
- data/test/test_gem_indexer.rb +673 -0
- data/test/test_gem_install_update_options.rb +68 -0
- data/test/test_gem_installer.rb +857 -0
- data/test/test_gem_local_remote_options.rb +97 -0
- data/test/test_gem_package_tar_header.rb +130 -0
- data/test/test_gem_package_tar_input.rb +112 -0
- data/test/test_gem_package_tar_output.rb +97 -0
- data/test/test_gem_package_tar_reader.rb +46 -0
- data/test/test_gem_package_tar_reader_entry.rb +109 -0
- data/test/test_gem_package_tar_writer.rb +144 -0
- data/test/test_gem_package_task.rb +59 -0
- data/test/test_gem_platform.rb +264 -0
- data/test/test_gem_remote_fetcher.rb +740 -0
- data/test/test_gem_requirement.rb +292 -0
- data/test/test_gem_server.rb +356 -0
- data/test/test_gem_silent_ui.rb +113 -0
- data/test/test_gem_source_index.rb +461 -0
- data/test/test_gem_spec_fetcher.rb +410 -0
- data/test/test_gem_specification.rb +1334 -0
- data/test/test_gem_stream_ui.rb +218 -0
- data/test/test_gem_text.rb +43 -0
- data/test/test_gem_uninstaller.rb +146 -0
- data/test/test_gem_validator.rb +63 -0
- data/test/test_gem_version.rb +181 -0
- data/test/test_gem_version_option.rb +89 -0
- data/test/test_kernel.rb +59 -0
- metadata +402 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/commands/list_command'
|
3
|
+
|
4
|
+
class TestGemCommandsListCommand < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@cmd = LibGems::Commands::ListCommand.new
|
10
|
+
|
11
|
+
util_setup_fake_fetcher
|
12
|
+
|
13
|
+
@si = util_setup_spec_fetcher @a1, @a2, @pl1
|
14
|
+
|
15
|
+
@fetcher.data["#{@gem_repo}Marshal.#{LibGems.marshal_version}"] = proc do
|
16
|
+
raise LibGems::RemoteFetcher::FetchError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_execute_installed
|
21
|
+
@cmd.handle_options %w[c --installed]
|
22
|
+
|
23
|
+
e = assert_raises LibGems::SystemExitException do
|
24
|
+
use_ui @ui do
|
25
|
+
@cmd.execute
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_equal 0, e.exit_code
|
30
|
+
|
31
|
+
assert_equal "true\n", @ui.output
|
32
|
+
|
33
|
+
assert_equal '', @ui.error
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/commands/lock_command'
|
3
|
+
|
4
|
+
class TestGemCommandsLockCommand < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@a1 = quick_gem 'a', '1'
|
10
|
+
@b1 = quick_gem 'b', '1' do |s|
|
11
|
+
s.add_runtime_dependency 'a'
|
12
|
+
end
|
13
|
+
|
14
|
+
@d1 = quick_gem 'd', '1' do |s|
|
15
|
+
s.add_runtime_dependency 'z'
|
16
|
+
end
|
17
|
+
|
18
|
+
@cmd = LibGems::Commands::LockCommand.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_execute
|
22
|
+
@cmd.handle_options %w[b-1]
|
23
|
+
|
24
|
+
use_ui @ui do
|
25
|
+
@cmd.execute
|
26
|
+
end
|
27
|
+
|
28
|
+
expected = <<-EXPECTED
|
29
|
+
require 'libgems'
|
30
|
+
gem 'b', '= 1'
|
31
|
+
gem 'a', '= 1'
|
32
|
+
EXPECTED
|
33
|
+
|
34
|
+
assert_equal expected, @ui.output
|
35
|
+
assert_equal '', @ui.error
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_execute_missing_dependency
|
39
|
+
@cmd.handle_options %w[d-1]
|
40
|
+
|
41
|
+
use_ui @ui do
|
42
|
+
@cmd.execute
|
43
|
+
end
|
44
|
+
|
45
|
+
expected = <<-EXPECTED
|
46
|
+
require 'libgems'
|
47
|
+
gem 'd', '= 1'
|
48
|
+
# Unable to satisfy 'z (>= 0, runtime)' from currently installed gems
|
49
|
+
EXPECTED
|
50
|
+
|
51
|
+
assert_equal expected, @ui.output
|
52
|
+
assert_equal '', @ui.error
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_execute_strict
|
56
|
+
@cmd.handle_options %w[c-1 --strict]
|
57
|
+
|
58
|
+
e = assert_raises LibGems::Exception do
|
59
|
+
use_ui @ui do
|
60
|
+
@cmd.execute
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_equal 'Could not find gem c-1, try using the full name', e.message
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/indexer'
|
3
|
+
require 'libgems/commands/mirror_command'
|
4
|
+
|
5
|
+
class TestGemCommandsMirrorCommand < RubyGemTestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
|
10
|
+
@cmd = LibGems::Commands::MirrorCommand.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_execute
|
14
|
+
util_make_gems
|
15
|
+
|
16
|
+
gems_dir = File.join @tempdir, 'gems'
|
17
|
+
mirror = File.join @tempdir, 'mirror'
|
18
|
+
|
19
|
+
FileUtils.mkdir_p gems_dir
|
20
|
+
FileUtils.mkdir_p mirror
|
21
|
+
|
22
|
+
Dir[File.join(@gemhome, 'cache', '*.gem')].each do |gem|
|
23
|
+
FileUtils.mv gem, gems_dir
|
24
|
+
end
|
25
|
+
|
26
|
+
use_ui @ui do
|
27
|
+
LibGems::Indexer.new(@tempdir).generate_index
|
28
|
+
end
|
29
|
+
|
30
|
+
orig_HOME = ENV['HOME']
|
31
|
+
ENV['HOME'] = @tempdir
|
32
|
+
LibGems.instance_variable_set :@user_home, nil
|
33
|
+
|
34
|
+
File.open File.join(LibGems.user_home, '.gemmirrorrc'), 'w' do |fp|
|
35
|
+
fp.puts "---"
|
36
|
+
# tempdir could be a drive+path (under windows)
|
37
|
+
if @tempdir.match(/[a-z]:/i)
|
38
|
+
fp.puts "- from: file:///#{@tempdir}"
|
39
|
+
else
|
40
|
+
fp.puts "- from: file://#{@tempdir}"
|
41
|
+
end
|
42
|
+
fp.puts " to: #{mirror}"
|
43
|
+
end
|
44
|
+
|
45
|
+
use_ui @ui do
|
46
|
+
@cmd.execute
|
47
|
+
end
|
48
|
+
|
49
|
+
assert File.exist?(File.join(mirror, 'gems', @a1.file_name))
|
50
|
+
assert File.exist?(File.join(mirror, 'gems', @a2.file_name))
|
51
|
+
assert File.exist?(File.join(mirror, 'gems', @b2.file_name))
|
52
|
+
assert File.exist?(File.join(mirror, 'gems', @c1_2.file_name))
|
53
|
+
assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}"))
|
54
|
+
ensure
|
55
|
+
orig_HOME.nil? ? ENV.delete('HOME') : ENV['HOME'] = orig_HOME
|
56
|
+
LibGems.instance_variable_set :@user_home, nil
|
57
|
+
end
|
58
|
+
|
59
|
+
end if ''.respond_to? :to_xs
|
60
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/commands/outdated_command'
|
3
|
+
|
4
|
+
class TestGemCommandsOutdatedCommand < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@cmd = LibGems::Commands::OutdatedCommand.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initialize
|
13
|
+
assert @cmd.handles?(%W[--platform #{LibGems::Platform.local}])
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_execute
|
17
|
+
local_01 = quick_gem 'foo', '0.1'
|
18
|
+
local_02 = quick_gem 'foo', '0.2'
|
19
|
+
remote_10 = quick_gem 'foo', '1.0'
|
20
|
+
remote_20 = quick_gem 'foo', '2.0'
|
21
|
+
|
22
|
+
remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name
|
23
|
+
FileUtils.rm remote_spec_file
|
24
|
+
|
25
|
+
remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name
|
26
|
+
FileUtils.rm remote_spec_file
|
27
|
+
|
28
|
+
@fetcher = LibGems::FakeFetcher.new
|
29
|
+
LibGems::RemoteFetcher.fetcher = @fetcher
|
30
|
+
|
31
|
+
util_setup_spec_fetcher remote_10, remote_20
|
32
|
+
|
33
|
+
use_ui @ui do @cmd.execute end
|
34
|
+
|
35
|
+
assert_equal "foo (0.2 < 2.0)\n", @ui.output
|
36
|
+
assert_equal "", @ui.error
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/commands/owner_command'
|
3
|
+
|
4
|
+
class TestGemCommandsOwnerCommand < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@fetcher = LibGems::FakeFetcher.new
|
10
|
+
LibGems::RemoteFetcher.fetcher = @fetcher
|
11
|
+
LibGems.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
|
12
|
+
|
13
|
+
@cmd = LibGems::Commands::OwnerCommand.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_show_owners
|
17
|
+
response = <<EOF
|
18
|
+
---
|
19
|
+
- email: user1@example.com
|
20
|
+
- email: user2@example.com
|
21
|
+
EOF
|
22
|
+
|
23
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
|
24
|
+
|
25
|
+
use_ui @ui do
|
26
|
+
@cmd.show_owners("freewill")
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_equal Net::HTTP::Get, @fetcher.last_request.class
|
30
|
+
assert_equal LibGems.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
|
31
|
+
|
32
|
+
assert_match %r{Owners for gem: freewill}, @ui.output
|
33
|
+
assert_match %r{- user1@example.com}, @ui.output
|
34
|
+
assert_match %r{- user2@example.com}, @ui.output
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_show_owners_denied
|
38
|
+
response = "You don't have permission to push to this gem"
|
39
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden']
|
40
|
+
|
41
|
+
assert_raises MockGemUi::TermError do
|
42
|
+
use_ui @ui do
|
43
|
+
@cmd.show_owners("freewill")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_match response, @ui.output
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_owners
|
51
|
+
response = "Owner added successfully."
|
52
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
|
53
|
+
|
54
|
+
use_ui @ui do
|
55
|
+
@cmd.add_owners("freewill", ["user-new1@example.com"])
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_equal Net::HTTP::Post, @fetcher.last_request.class
|
59
|
+
assert_equal LibGems.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
|
60
|
+
assert_equal "email=user-new1%40example.com", @fetcher.last_request.body
|
61
|
+
|
62
|
+
assert_match response, @ui.output
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_add_owners_denied
|
66
|
+
response = "You don't have permission to push to this gem"
|
67
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
|
68
|
+
|
69
|
+
assert_raises MockGemUi::TermError do
|
70
|
+
use_ui @ui do
|
71
|
+
@cmd.add_owners("freewill", ["user-new1@example.com"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_match response, @ui.output
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_remove_owners
|
79
|
+
response = "Owner removed successfully."
|
80
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
|
81
|
+
|
82
|
+
use_ui @ui do
|
83
|
+
@cmd.remove_owners("freewill", ["user-remove1@example.com"])
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_equal Net::HTTP::Delete, @fetcher.last_request.class
|
87
|
+
assert_equal LibGems.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
|
88
|
+
assert_equal "email=user-remove1%40example.com", @fetcher.last_request.body
|
89
|
+
|
90
|
+
assert_match response, @ui.output
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_remove_owners_denied
|
94
|
+
response = "You don't have permission to push to this gem"
|
95
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
|
96
|
+
|
97
|
+
assert_raises MockGemUi::TermError do
|
98
|
+
use_ui @ui do
|
99
|
+
@cmd.remove_owners("freewill", ["user-remove1@example.com"])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_match response, @ui.output
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/commands/pristine_command'
|
3
|
+
|
4
|
+
class TestGemCommandsPristineCommand < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@cmd = LibGems::Commands::PristineCommand.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_execute
|
12
|
+
a = quick_gem 'a' do |s| s.executables = %w[foo] end
|
13
|
+
FileUtils.mkdir_p File.join(@tempdir, 'bin')
|
14
|
+
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
|
15
|
+
fp.puts "#!/usr/bin/ruby"
|
16
|
+
end
|
17
|
+
|
18
|
+
install_gem a
|
19
|
+
|
20
|
+
foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
|
21
|
+
|
22
|
+
File.open foo_path, 'w' do |io|
|
23
|
+
io.puts 'I changed it!'
|
24
|
+
end
|
25
|
+
|
26
|
+
@cmd.options[:args] = %w[a]
|
27
|
+
|
28
|
+
use_ui @ui do
|
29
|
+
@cmd.execute
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
|
33
|
+
|
34
|
+
out = @ui.output.split "\n"
|
35
|
+
|
36
|
+
assert_equal "Restoring gem(s) to pristine condition...", out.shift
|
37
|
+
assert_equal "Restored #{a.full_name}", out.shift
|
38
|
+
assert_empty out, out.inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_execute_all
|
42
|
+
a = quick_gem 'a' do |s| s.executables = %w[foo] end
|
43
|
+
FileUtils.mkdir_p File.join(@tempdir, 'bin')
|
44
|
+
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
|
45
|
+
fp.puts "#!/usr/bin/ruby"
|
46
|
+
end
|
47
|
+
|
48
|
+
install_gem a
|
49
|
+
|
50
|
+
gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
|
51
|
+
|
52
|
+
FileUtils.rm gem_bin
|
53
|
+
|
54
|
+
@cmd.handle_options %w[--all]
|
55
|
+
|
56
|
+
use_ui @ui do
|
57
|
+
@cmd.execute
|
58
|
+
end
|
59
|
+
|
60
|
+
assert File.exist?(gem_bin)
|
61
|
+
|
62
|
+
out = @ui.output.split "\n"
|
63
|
+
|
64
|
+
assert_equal "Restoring gem(s) to pristine condition...", out.shift
|
65
|
+
assert_equal "Restored #{a.full_name}", out.shift
|
66
|
+
assert_empty out, out.inspect
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_execute_missing_cache_gem
|
70
|
+
a = quick_gem 'a' do |s| s.executables = %w[foo] end
|
71
|
+
FileUtils.mkdir_p File.join(@tempdir, 'bin')
|
72
|
+
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
|
73
|
+
fp.puts "#!/usr/bin/ruby"
|
74
|
+
end
|
75
|
+
|
76
|
+
install_gem a
|
77
|
+
|
78
|
+
FileUtils.rm File.join(@gemhome, 'cache', a.file_name)
|
79
|
+
|
80
|
+
@cmd.options[:args] = %w[a]
|
81
|
+
|
82
|
+
use_ui @ui do
|
83
|
+
@cmd.execute
|
84
|
+
end
|
85
|
+
|
86
|
+
out = @ui.output.split "\n"
|
87
|
+
|
88
|
+
assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
|
89
|
+
assert_empty out, out.inspect
|
90
|
+
|
91
|
+
assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n",
|
92
|
+
@ui.error
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_execute_no_gem
|
96
|
+
@cmd.options[:args] = %w[]
|
97
|
+
|
98
|
+
e = assert_raises LibGems::CommandLineError do
|
99
|
+
use_ui @ui do
|
100
|
+
@cmd.execute
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
assert_match %r|specify a gem name|, e.message
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/commands/push_command'
|
3
|
+
|
4
|
+
class TestGemCommandsPushCommand < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@gems_dir = File.join @tempdir, 'gems'
|
10
|
+
@cache_dir = File.join @gemhome, 'cache'
|
11
|
+
FileUtils.mkdir @gems_dir
|
12
|
+
LibGems.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
|
13
|
+
@spec, @path = util_gem("freewill", "1.0.0")
|
14
|
+
|
15
|
+
@fetcher = LibGems::FakeFetcher.new
|
16
|
+
LibGems::RemoteFetcher.fetcher = @fetcher
|
17
|
+
|
18
|
+
@cmd = LibGems::Commands::PushCommand.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_battery
|
22
|
+
use_ui @ui do
|
23
|
+
@cmd.send_gem(@path)
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_match %r{Pushing gem to #{LibGems.host}...}, @ui.output
|
27
|
+
|
28
|
+
assert_equal Net::HTTP::Post, @fetcher.last_request.class
|
29
|
+
assert_equal LibGems.read_binary(@path), @fetcher.last_request.body
|
30
|
+
assert_equal File.size(@path), @fetcher.last_request["Content-Length"].to_i
|
31
|
+
assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"]
|
32
|
+
assert_equal LibGems.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
|
33
|
+
|
34
|
+
assert_match @response, @ui.output
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_sending_gem_default
|
38
|
+
@response = "Successfully registered gem: freewill (1.0.0)"
|
39
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems"] = [@response, 200, 'OK']
|
40
|
+
|
41
|
+
send_battery
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_sending_gem_host
|
45
|
+
@response = "Successfully registered gem: freewill (1.0.0)"
|
46
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems"] = [@response, 200, 'OK']
|
47
|
+
@cmd.options[:host] = "#{LibGems.host}"
|
48
|
+
|
49
|
+
send_battery
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_sending_gem_ENV
|
53
|
+
@response = "Successfully registered gem: freewill (1.0.0)"
|
54
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems"] = [@response, 200, 'OK']
|
55
|
+
ENV["RUBYGEMS_HOST"] = "#{LibGems.host}"
|
56
|
+
|
57
|
+
send_battery
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_raises_error_with_no_arguments
|
61
|
+
def @cmd.sign_in; end
|
62
|
+
assert_raises LibGems::CommandLineError do
|
63
|
+
@cmd.execute
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_sending_gem_denied
|
68
|
+
response = "You don't have permission to push to this gem"
|
69
|
+
@fetcher.data["#{LibGems.host}/api/v1/gems"] = [response, 403, 'Forbidden']
|
70
|
+
|
71
|
+
assert_raises MockGemUi::TermError do
|
72
|
+
use_ui @ui do
|
73
|
+
@cmd.send_gem(@path)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_match response, @ui.output
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|