libgems 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +113 -0
  6. data/lib/gauntlet_libgems.rb +50 -0
  7. data/lib/libgems.rb +1246 -0
  8. data/lib/libgems/builder.rb +102 -0
  9. data/lib/libgems/command.rb +534 -0
  10. data/lib/libgems/command_manager.rb +182 -0
  11. data/lib/libgems/commands/build_command.rb +53 -0
  12. data/lib/libgems/commands/cert_command.rb +86 -0
  13. data/lib/libgems/commands/check_command.rb +80 -0
  14. data/lib/libgems/commands/cleanup_command.rb +106 -0
  15. data/lib/libgems/commands/contents_command.rb +98 -0
  16. data/lib/libgems/commands/dependency_command.rb +195 -0
  17. data/lib/libgems/commands/environment_command.rb +133 -0
  18. data/lib/libgems/commands/fetch_command.rb +67 -0
  19. data/lib/libgems/commands/generate_index_command.rb +133 -0
  20. data/lib/libgems/commands/help_command.rb +172 -0
  21. data/lib/libgems/commands/install_command.rb +178 -0
  22. data/lib/libgems/commands/list_command.rb +35 -0
  23. data/lib/libgems/commands/lock_command.rb +110 -0
  24. data/lib/libgems/commands/mirror_command.rb +111 -0
  25. data/lib/libgems/commands/outdated_command.rb +33 -0
  26. data/lib/libgems/commands/owner_command.rb +75 -0
  27. data/lib/libgems/commands/pristine_command.rb +93 -0
  28. data/lib/libgems/commands/push_command.rb +56 -0
  29. data/lib/libgems/commands/query_command.rb +280 -0
  30. data/lib/libgems/commands/rdoc_command.rb +91 -0
  31. data/lib/libgems/commands/search_command.rb +31 -0
  32. data/lib/libgems/commands/server_command.rb +86 -0
  33. data/lib/libgems/commands/sources_command.rb +157 -0
  34. data/lib/libgems/commands/specification_command.rb +125 -0
  35. data/lib/libgems/commands/stale_command.rb +27 -0
  36. data/lib/libgems/commands/uninstall_command.rb +83 -0
  37. data/lib/libgems/commands/unpack_command.rb +121 -0
  38. data/lib/libgems/commands/update_command.rb +160 -0
  39. data/lib/libgems/commands/which_command.rb +86 -0
  40. data/lib/libgems/config_file.rb +345 -0
  41. data/lib/libgems/custom_require.rb +44 -0
  42. data/lib/libgems/defaults.rb +101 -0
  43. data/lib/libgems/dependency.rb +227 -0
  44. data/lib/libgems/dependency_installer.rb +286 -0
  45. data/lib/libgems/dependency_list.rb +208 -0
  46. data/lib/libgems/doc_manager.rb +242 -0
  47. data/lib/libgems/errors.rb +35 -0
  48. data/lib/libgems/exceptions.rb +91 -0
  49. data/lib/libgems/ext.rb +18 -0
  50. data/lib/libgems/ext/builder.rb +56 -0
  51. data/lib/libgems/ext/configure_builder.rb +25 -0
  52. data/lib/libgems/ext/ext_conf_builder.rb +24 -0
  53. data/lib/libgems/ext/rake_builder.rb +39 -0
  54. data/lib/libgems/format.rb +81 -0
  55. data/lib/libgems/gem_openssl.rb +92 -0
  56. data/lib/libgems/gem_path_searcher.rb +100 -0
  57. data/lib/libgems/gem_runner.rb +79 -0
  58. data/lib/libgems/gemcutter_utilities.rb +49 -0
  59. data/lib/libgems/indexer.rb +720 -0
  60. data/lib/libgems/install_update_options.rb +125 -0
  61. data/lib/libgems/installer.rb +604 -0
  62. data/lib/libgems/local_remote_options.rb +135 -0
  63. data/lib/libgems/old_format.rb +153 -0
  64. data/lib/libgems/package.rb +97 -0
  65. data/lib/libgems/package/f_sync_dir.rb +23 -0
  66. data/lib/libgems/package/tar_header.rb +266 -0
  67. data/lib/libgems/package/tar_input.rb +222 -0
  68. data/lib/libgems/package/tar_output.rb +144 -0
  69. data/lib/libgems/package/tar_reader.rb +106 -0
  70. data/lib/libgems/package/tar_reader/entry.rb +141 -0
  71. data/lib/libgems/package/tar_writer.rb +241 -0
  72. data/lib/libgems/package_task.rb +126 -0
  73. data/lib/libgems/platform.rb +183 -0
  74. data/lib/libgems/remote_fetcher.rb +414 -0
  75. data/lib/libgems/require_paths_builder.rb +18 -0
  76. data/lib/libgems/requirement.rb +153 -0
  77. data/lib/libgems/security.rb +814 -0
  78. data/lib/libgems/server.rb +872 -0
  79. data/lib/libgems/source_index.rb +597 -0
  80. data/lib/libgems/source_info_cache.rb +395 -0
  81. data/lib/libgems/source_info_cache_entry.rb +56 -0
  82. data/lib/libgems/spec_fetcher.rb +337 -0
  83. data/lib/libgems/specification.rb +1487 -0
  84. data/lib/libgems/test_utilities.rb +147 -0
  85. data/lib/libgems/text.rb +65 -0
  86. data/lib/libgems/uninstaller.rb +278 -0
  87. data/lib/libgems/user_interaction.rb +527 -0
  88. data/lib/libgems/validator.rb +240 -0
  89. data/lib/libgems/version.rb +316 -0
  90. data/lib/libgems/version_option.rb +65 -0
  91. data/lib/rbconfig/datadir.rb +20 -0
  92. data/test/bogussources.rb +8 -0
  93. data/test/data/gem-private_key.pem +27 -0
  94. data/test/data/gem-public_cert.pem +20 -0
  95. data/test/fake_certlib/openssl.rb +7 -0
  96. data/test/foo/discover.rb +0 -0
  97. data/test/gem_installer_test_case.rb +97 -0
  98. data/test/gem_package_tar_test_case.rb +132 -0
  99. data/test/gemutilities.rb +605 -0
  100. data/test/insure_session.rb +43 -0
  101. data/test/mockgemui.rb +56 -0
  102. data/test/plugin/exception/libgems_plugin.rb +2 -0
  103. data/test/plugin/load/libgems_plugin.rb +1 -0
  104. data/test/plugin/standarderror/libgems_plugin.rb +2 -0
  105. data/test/private_key.pem +27 -0
  106. data/test/public_cert.pem +20 -0
  107. data/test/rubygems_plugin.rb +21 -0
  108. data/test/simple_gem.rb +66 -0
  109. data/test/test_config.rb +12 -0
  110. data/test/test_gem.rb +780 -0
  111. data/test/test_gem_builder.rb +27 -0
  112. data/test/test_gem_command.rb +178 -0
  113. data/test/test_gem_command_manager.rb +207 -0
  114. data/test/test_gem_commands_build_command.rb +74 -0
  115. data/test/test_gem_commands_cert_command.rb +124 -0
  116. data/test/test_gem_commands_check_command.rb +18 -0
  117. data/test/test_gem_commands_contents_command.rb +156 -0
  118. data/test/test_gem_commands_dependency_command.rb +216 -0
  119. data/test/test_gem_commands_environment_command.rb +144 -0
  120. data/test/test_gem_commands_fetch_command.rb +76 -0
  121. data/test/test_gem_commands_generate_index_command.rb +135 -0
  122. data/test/test_gem_commands_install_command.rb +315 -0
  123. data/test/test_gem_commands_list_command.rb +36 -0
  124. data/test/test_gem_commands_lock_command.rb +68 -0
  125. data/test/test_gem_commands_mirror_command.rb +60 -0
  126. data/test/test_gem_commands_outdated_command.rb +40 -0
  127. data/test/test_gem_commands_owner_command.rb +105 -0
  128. data/test/test_gem_commands_pristine_command.rb +108 -0
  129. data/test/test_gem_commands_push_command.rb +81 -0
  130. data/test/test_gem_commands_query_command.rb +426 -0
  131. data/test/test_gem_commands_server_command.rb +59 -0
  132. data/test/test_gem_commands_sources_command.rb +209 -0
  133. data/test/test_gem_commands_specification_command.rb +139 -0
  134. data/test/test_gem_commands_stale_command.rb +38 -0
  135. data/test/test_gem_commands_uninstall_command.rb +83 -0
  136. data/test/test_gem_commands_unpack_command.rb +199 -0
  137. data/test/test_gem_commands_update_command.rb +207 -0
  138. data/test/test_gem_commands_which_command.rb +66 -0
  139. data/test/test_gem_config_file.rb +287 -0
  140. data/test/test_gem_dependency.rb +149 -0
  141. data/test/test_gem_dependency_installer.rb +661 -0
  142. data/test/test_gem_dependency_list.rb +230 -0
  143. data/test/test_gem_doc_manager.rb +31 -0
  144. data/test/test_gem_ext_configure_builder.rb +84 -0
  145. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  146. data/test/test_gem_ext_rake_builder.rb +81 -0
  147. data/test/test_gem_format.rb +70 -0
  148. data/test/test_gem_gem_path_searcher.rb +78 -0
  149. data/test/test_gem_gem_runner.rb +45 -0
  150. data/test/test_gem_gemcutter_utilities.rb +103 -0
  151. data/test/test_gem_indexer.rb +673 -0
  152. data/test/test_gem_install_update_options.rb +68 -0
  153. data/test/test_gem_installer.rb +857 -0
  154. data/test/test_gem_local_remote_options.rb +97 -0
  155. data/test/test_gem_package_tar_header.rb +130 -0
  156. data/test/test_gem_package_tar_input.rb +112 -0
  157. data/test/test_gem_package_tar_output.rb +97 -0
  158. data/test/test_gem_package_tar_reader.rb +46 -0
  159. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  160. data/test/test_gem_package_tar_writer.rb +144 -0
  161. data/test/test_gem_package_task.rb +59 -0
  162. data/test/test_gem_platform.rb +264 -0
  163. data/test/test_gem_remote_fetcher.rb +740 -0
  164. data/test/test_gem_requirement.rb +292 -0
  165. data/test/test_gem_server.rb +356 -0
  166. data/test/test_gem_silent_ui.rb +113 -0
  167. data/test/test_gem_source_index.rb +461 -0
  168. data/test/test_gem_spec_fetcher.rb +410 -0
  169. data/test/test_gem_specification.rb +1334 -0
  170. data/test/test_gem_stream_ui.rb +218 -0
  171. data/test/test_gem_text.rb +43 -0
  172. data/test/test_gem_uninstaller.rb +146 -0
  173. data/test/test_gem_validator.rb +63 -0
  174. data/test/test_gem_version.rb +181 -0
  175. data/test/test_gem_version_option.rb +89 -0
  176. data/test/test_kernel.rb +59 -0
  177. metadata +402 -0
@@ -0,0 +1,124 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/commands/cert_command'
3
+
4
+ unless defined? OpenSSL then
5
+ warn "`gem cert` tests are being skipped, module OpenSSL not found"
6
+ end
7
+
8
+ class TestGemCommandsCertCommand < RubyGemTestCase
9
+
10
+ def setup
11
+ super
12
+
13
+ @orig_security_trust_dir = LibGems::Security::OPT[:trust_dir]
14
+ LibGems::Security::OPT[:trust_dir] = @tempdir
15
+
16
+ @cmd = LibGems::Commands::CertCommand.new
17
+
18
+ root = File.expand_path(File.dirname(__FILE__))
19
+
20
+ FileUtils.cp File.join(root, 'data', 'gem-private_key.pem'), @tempdir
21
+ FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir
22
+
23
+ @cert_file_name = File.join @tempdir, 'gem-public_cert.pem'
24
+ @pkey_file_name = File.join @tempdir, 'gem-private_key.pem'
25
+ end
26
+
27
+ def teardown
28
+ LibGems::Security::OPT[:trust_dir] = @orig_security_trust_dir
29
+
30
+ super
31
+ end
32
+
33
+ def test_execute_add
34
+ use_ui @ui do
35
+ @cmd.send :handle_options, %W[--add #{@cert_file_name}]
36
+ end
37
+
38
+ assert_equal "Added '/CN=rubygems/DC=example/DC=com'\n", @ui.output
39
+ assert_equal '', @ui.error
40
+ end
41
+
42
+ def test_execute_build
43
+ FileUtils.rm @cert_file_name
44
+ FileUtils.rm @pkey_file_name
45
+
46
+ use_ui @ui do
47
+ Dir.chdir @tempdir do
48
+ @cmd.send :handle_options, %W[--build nobody@example.com]
49
+ end
50
+ end
51
+
52
+ output = @ui.output.split "\n"
53
+
54
+ assert_equal 'Public Cert: gem-public_cert.pem', output.shift
55
+ assert_equal 'Private Key: gem-private_key.pem', output.shift
56
+ assert_equal 'Don\'t forget to move the key file to somewhere private...',
57
+ output.shift
58
+ assert_equal [], output
59
+
60
+ assert_equal '', @ui.error
61
+
62
+ assert File.exist?(File.join(@tempdir, 'gem-private_key.pem'))
63
+ assert File.exist?(File.join(@tempdir, 'gem-public_cert.pem'))
64
+ end
65
+
66
+ def test_execute_certificate
67
+ use_ui @ui do
68
+ @cmd.send :handle_options, %W[--certificate #{@cert_file_name}]
69
+ end
70
+
71
+ assert_equal '', @ui.output
72
+ assert_equal '', @ui.error
73
+
74
+ assert_equal File.read(@cert_file_name),
75
+ LibGems::Security::OPT[:issuer_cert].to_s
76
+ end
77
+
78
+ def test_execute_list
79
+ use_ui @ui do
80
+ @cmd.send :handle_options, %W[--list]
81
+ end
82
+
83
+ assert_equal "/CN=rubygems/DC=example/DC=com\n", @ui.output
84
+ assert_equal '', @ui.error
85
+ end
86
+
87
+ def test_execute_private_key
88
+ use_ui @ui do
89
+ @cmd.send :handle_options, %W[--private-key #{@pkey_file_name}]
90
+ end
91
+
92
+ assert_equal '', @ui.output
93
+ assert_equal '', @ui.error
94
+
95
+ assert_equal File.read(@pkey_file_name),
96
+ LibGems::Security::OPT[:issuer_key].to_s
97
+ end
98
+
99
+ def test_execute_remove
100
+ use_ui @ui do
101
+ @cmd.send :handle_options, %W[--remove rubygems]
102
+ end
103
+
104
+ assert_equal "Removed '/CN=rubygems/DC=example/DC=com'\n", @ui.output
105
+ assert_equal '', @ui.error
106
+
107
+ refute File.exist?(@cert_file_name)
108
+ end
109
+
110
+ def test_execute_sign
111
+ use_ui @ui do
112
+ @cmd.send :handle_options, %W[
113
+ -K #{@pkey_file_name} -C #{@cert_file_name} --sign #{@cert_file_name}
114
+ ]
115
+ end
116
+
117
+ assert_equal '', @ui.output
118
+ assert_equal '', @ui.error
119
+
120
+ # HACK this test sucks
121
+ end
122
+
123
+ end if defined? OpenSSL
124
+
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/commands/check_command'
3
+
4
+ class TestGemCommandsCheckCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::Commands::CheckCommand.new
10
+ end
11
+
12
+ def test_initialize
13
+ assert_equal "check", @cmd.command
14
+ assert_equal "gem check", @cmd.program_name
15
+ assert_match(/Check/, @cmd.summary)
16
+ end
17
+
18
+ end
@@ -0,0 +1,156 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/commands/contents_command'
3
+
4
+ class TestGemCommandsContentsCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::Commands::ContentsCommand.new
10
+ end
11
+
12
+ def test_execute
13
+ @cmd.options[:args] = %w[foo]
14
+ quick_gem 'foo' do |gem|
15
+ gem.files = %w[lib/foo.rb Rakefile]
16
+ end
17
+
18
+ use_ui @ui do
19
+ @cmd.execute
20
+ end
21
+
22
+ assert_match %r|lib/foo\.rb|, @ui.output
23
+ assert_match %r|Rakefile|, @ui.output
24
+ assert_equal "", @ui.error
25
+ end
26
+
27
+ def test_execute_all
28
+ @cmd.options[:all] = true
29
+
30
+ quick_gem 'foo' do |gem|
31
+ gem.files = %w[lib/foo.rb Rakefile]
32
+ end
33
+
34
+ quick_gem 'bar' do |gem|
35
+ gem.files = %w[lib/bar.rb Rakefile]
36
+ end
37
+
38
+ use_ui @ui do
39
+ @cmd.execute
40
+ end
41
+
42
+ assert_match %r|lib/foo\.rb|, @ui.output
43
+ assert_match %r|lib/bar\.rb|, @ui.output
44
+ assert_match %r|Rakefile|, @ui.output
45
+ assert_equal "", @ui.error
46
+ end
47
+
48
+ def test_execute_bad_gem
49
+ @cmd.options[:args] = %w[foo]
50
+
51
+ assert_raises MockGemUi::TermError do
52
+ use_ui @ui do
53
+ @cmd.execute
54
+ end
55
+ end
56
+
57
+ assert_match %r|Unable to find gem 'foo' in default gem paths|, @ui.output
58
+ assert_match %r|Directories searched:|, @ui.output
59
+ assert_equal "", @ui.error
60
+ end
61
+
62
+ def test_execute_exact_match
63
+ @cmd.options[:args] = %w[foo]
64
+ quick_gem 'foo' do |gem|
65
+ gem.files = %w[lib/foo.rb Rakefile]
66
+ end
67
+
68
+ quick_gem 'foo_bar' do |gem|
69
+ gem.files = %w[lib/foo_bar.rb Rakefile]
70
+ end
71
+
72
+ use_ui @ui do
73
+ @cmd.execute
74
+ end
75
+
76
+ assert_match %r|lib/foo\.rb|, @ui.output
77
+ assert_match %r|Rakefile|, @ui.output
78
+ assert_equal "", @ui.error
79
+ end
80
+
81
+ def test_execute_lib_only
82
+ @cmd.options[:args] = %w[foo]
83
+ @cmd.options[:lib_only] = true
84
+
85
+ quick_gem 'foo' do |gem|
86
+ gem.files = %w[lib/foo.rb Rakefile]
87
+ end
88
+
89
+ use_ui @ui do
90
+ @cmd.execute
91
+ end
92
+
93
+ assert_match %r|lib/foo\.rb|, @ui.output
94
+ refute_match %r|Rakefile|, @ui.output
95
+
96
+ assert_equal "", @ui.error
97
+ end
98
+
99
+ def test_execute_multiple
100
+ @cmd.options[:args] = %w[foo bar]
101
+ quick_gem 'foo' do |gem|
102
+ gem.files = %w[lib/foo.rb Rakefile]
103
+ end
104
+
105
+ quick_gem 'bar' do |gem|
106
+ gem.files = %w[lib/bar.rb Rakefile]
107
+ end
108
+
109
+ use_ui @ui do
110
+ @cmd.execute
111
+ end
112
+
113
+ assert_match %r|lib/foo\.rb|, @ui.output
114
+ assert_match %r|lib/bar\.rb|, @ui.output
115
+ assert_match %r|Rakefile|, @ui.output
116
+ assert_equal "", @ui.error
117
+ end
118
+
119
+ def test_execute_no_prefix
120
+ @cmd.options[:args] = %w[foo]
121
+ @cmd.options[:prefix] = false
122
+
123
+ quick_gem 'foo' do |gem|
124
+ gem.files = %w[lib/foo.rb Rakefile]
125
+ end
126
+
127
+ use_ui @ui do
128
+ @cmd.execute
129
+ end
130
+
131
+ expected = <<-EOF
132
+ lib/foo.rb
133
+ Rakefile
134
+ EOF
135
+
136
+ assert_equal expected, @ui.output
137
+
138
+ assert_equal "", @ui.error
139
+ end
140
+
141
+ def test_handle_options
142
+ refute @cmd.options[:lib_only]
143
+ assert @cmd.options[:prefix]
144
+ assert_empty @cmd.options[:specdirs]
145
+ assert_nil @cmd.options[:version]
146
+
147
+ @cmd.send :handle_options, %w[-l -s foo --version 0.0.2 --no-prefix]
148
+
149
+ assert @cmd.options[:lib_only]
150
+ refute @cmd.options[:prefix]
151
+ assert_equal %w[foo], @cmd.options[:specdirs]
152
+ assert_equal LibGems::Requirement.new('0.0.2'), @cmd.options[:version]
153
+ end
154
+
155
+ end
156
+
@@ -0,0 +1,216 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/commands/dependency_command'
3
+
4
+ class TestGemCommandsDependencyCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::Commands::DependencyCommand.new
10
+ @cmd.options[:domain] = :local
11
+
12
+ util_setup_fake_fetcher true
13
+ end
14
+
15
+ def test_execute
16
+ quick_gem 'foo' do |gem|
17
+ gem.add_dependency 'bar', '> 1'
18
+ gem.add_dependency 'baz', '> 1'
19
+ end
20
+
21
+ LibGems.source_index = nil
22
+
23
+ @cmd.options[:args] = %w[foo]
24
+
25
+ use_ui @ui do
26
+ @cmd.execute
27
+ end
28
+
29
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n baz (> 1, runtime)\n\n",
30
+ @ui.output
31
+ assert_equal '', @ui.error
32
+ end
33
+
34
+ def test_execute_no_args
35
+ LibGems.source_index = nil
36
+
37
+ @cmd.options[:args] = []
38
+
39
+ use_ui @ui do
40
+ @cmd.execute
41
+ end
42
+
43
+ expected = <<-EOF
44
+ Gem a-1
45
+
46
+ Gem a-2.a
47
+
48
+ Gem a-2
49
+
50
+ Gem a-3.a
51
+
52
+ Gem a_evil-9
53
+
54
+ Gem b-2
55
+
56
+ Gem c-1.2
57
+
58
+ Gem pl-1-x86-linux
59
+
60
+ EOF
61
+
62
+ assert_equal expected, @ui.output
63
+ assert_equal '', @ui.error
64
+ end
65
+
66
+ def test_execute_no_match
67
+ @cmd.options[:args] = %w[foo]
68
+
69
+ assert_raises MockGemUi::TermError do
70
+ use_ui @ui do
71
+ @cmd.execute
72
+ end
73
+ end
74
+
75
+ assert_equal "No gems found matching foo (>= 0)\n", @ui.output
76
+ assert_equal '', @ui.error
77
+ end
78
+
79
+ def test_execute_pipe_format
80
+ quick_gem 'foo' do |gem|
81
+ gem.add_dependency 'bar', '> 1'
82
+ end
83
+
84
+ @cmd.options[:args] = %w[foo]
85
+ @cmd.options[:pipe_format] = true
86
+
87
+ use_ui @ui do
88
+ @cmd.execute
89
+ end
90
+
91
+ assert_equal "bar --version '> 1'\n", @ui.output
92
+ assert_equal '', @ui.error
93
+ end
94
+
95
+ def test_execute_regexp
96
+ LibGems.source_index = nil
97
+
98
+ @cmd.options[:args] = %w[/[ab]/]
99
+
100
+ use_ui @ui do
101
+ @cmd.execute
102
+ end
103
+
104
+ expected = <<-EOF
105
+ Gem a-1
106
+
107
+ Gem a-2.a
108
+
109
+ Gem a-2
110
+
111
+ Gem a-3.a
112
+
113
+ Gem a_evil-9
114
+
115
+ Gem b-2
116
+
117
+ EOF
118
+
119
+ assert_equal expected, @ui.output
120
+ assert_equal '', @ui.error
121
+ end
122
+
123
+ def test_execute_reverse
124
+ quick_gem 'foo' do |gem|
125
+ gem.add_dependency 'bar', '> 1'
126
+ end
127
+
128
+ quick_gem 'baz' do |gem|
129
+ gem.add_dependency 'foo'
130
+ end
131
+
132
+ LibGems.source_index = nil
133
+
134
+ @cmd.options[:args] = %w[foo]
135
+ @cmd.options[:reverse_dependencies] = true
136
+
137
+ use_ui @ui do
138
+ @cmd.execute
139
+ end
140
+
141
+ expected = <<-EOF
142
+ Gem foo-2
143
+ bar (> 1, runtime)
144
+ Used by
145
+ baz-2 (foo (>= 0, runtime))
146
+
147
+ EOF
148
+
149
+ assert_equal expected, @ui.output
150
+ assert_equal '', @ui.error
151
+ end
152
+
153
+ def test_execute_reverse_remote
154
+ @cmd.options[:args] = %w[foo]
155
+ @cmd.options[:reverse_dependencies] = true
156
+ @cmd.options[:domain] = :remote
157
+
158
+ assert_raises MockGemUi::TermError do
159
+ use_ui @ui do
160
+ @cmd.execute
161
+ end
162
+ end
163
+
164
+ expected = <<-EOF
165
+ ERROR: Only reverse dependencies for local gems are supported.
166
+ EOF
167
+
168
+ assert_equal '', @ui.output
169
+ assert_equal expected, @ui.error
170
+ end
171
+
172
+ def test_execute_remote
173
+ foo = quick_gem 'foo' do |gem|
174
+ gem.add_dependency 'bar', '> 1'
175
+ end
176
+
177
+ @fetcher = LibGems::FakeFetcher.new
178
+ LibGems::RemoteFetcher.fetcher = @fetcher
179
+
180
+ util_setup_spec_fetcher foo
181
+
182
+ FileUtils.rm File.join(@gemhome, 'specifications', foo.spec_name)
183
+
184
+ @cmd.options[:args] = %w[foo]
185
+ @cmd.options[:domain] = :remote
186
+
187
+ use_ui @ui do
188
+ @cmd.execute
189
+ end
190
+
191
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
192
+ assert_equal '', @ui.error
193
+ end
194
+
195
+ def test_execute_prerelease
196
+ @fetcher = LibGems::FakeFetcher.new
197
+ LibGems::RemoteFetcher.fetcher = @fetcher
198
+
199
+ util_setup_spec_fetcher @a2_pre
200
+
201
+ FileUtils.rm File.join(@gemhome, 'specifications', @a2_pre.spec_name)
202
+
203
+ @cmd.options[:args] = %w[a]
204
+ @cmd.options[:domain] = :remote
205
+ @cmd.options[:prerelease] = true
206
+
207
+ use_ui @ui do
208
+ @cmd.execute
209
+ end
210
+
211
+ assert_equal "Gem a-2.a\n\n", @ui.output
212
+ assert_equal '', @ui.error
213
+ end
214
+
215
+ end
216
+