2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/dependency_command'
5 class TestGemCommandsDependencyCommand < RubyGemTestCase
10 @cmd = Gem::Commands::DependencyCommand.new
11 @cmd.options[:domain] = :local
13 util_setup_fake_fetcher
17 quick_gem 'foo' do |gem|
18 gem.add_dependency 'bar', '> 1'
21 Gem.source_index = nil
23 @cmd.options[:args] = %w[foo]
29 assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
30 assert_equal '', @ui.error
33 def test_execute_no_match
34 @cmd.options[:args] = %w[foo]
36 assert_raise MockGemUi::TermError do
42 assert_equal "No gems found matching foo (>= 0)\n", @ui.output
43 assert_equal '', @ui.error
46 def test_execute_pipe_format
47 quick_gem 'foo' do |gem|
48 gem.add_dependency 'bar', '> 1'
51 @cmd.options[:args] = %w[foo]
52 @cmd.options[:pipe_format] = true
58 assert_equal "bar --version '> 1'\n", @ui.output
59 assert_equal '', @ui.error
62 def test_execute_reverse
63 quick_gem 'foo' do |gem|
64 gem.add_dependency 'bar', '> 1'
67 quick_gem 'baz' do |gem|
68 gem.add_dependency 'foo'
71 Gem.source_index = nil
73 @cmd.options[:args] = %w[foo]
74 @cmd.options[:reverse_dependencies] = true
84 baz-2 (foo (>= 0, runtime))
88 assert_equal expected, @ui.output
89 assert_equal '', @ui.error
92 def test_execute_reverse_remote
93 @cmd.options[:args] = %w[foo]
94 @cmd.options[:reverse_dependencies] = true
95 @cmd.options[:domain] = :remote
97 assert_raise MockGemUi::TermError do
104 ERROR: Only reverse dependencies for local gems are supported.
107 assert_equal '', @ui.output
108 assert_equal expected, @ui.error
111 def test_execute_remote
112 foo = quick_gem 'foo' do |gem|
113 gem.add_dependency 'bar', '> 1'
116 @fetcher = Gem::FakeFetcher.new
117 Gem::RemoteFetcher.fetcher = @fetcher
119 util_setup_spec_fetcher foo
121 FileUtils.rm File.join(@gemhome, 'specifications',
122 "#{foo.full_name}.gemspec")
124 @cmd.options[:args] = %w[foo]
125 @cmd.options[:domain] = :remote
131 assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
132 assert_equal '', @ui.error
135 def test_execute_remote_legacy
136 foo = quick_gem 'foo' do |gem|
137 gem.add_dependency 'bar', '> 1'
140 @fetcher = Gem::FakeFetcher.new
141 Gem::RemoteFetcher.fetcher = @fetcher
143 Gem::SpecFetcher.fetcher = nil
144 si = util_setup_source_info_cache foo
146 @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
147 @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
150 @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
152 FileUtils.rm File.join(@gemhome, 'specifications',
153 "#{foo.full_name}.gemspec")
155 @cmd.options[:args] = %w[foo]
156 @cmd.options[:domain] = :remote
162 assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
165 WARNING: RubyGems 1.2+ index not found for:
168 RubyGems will revert to legacy indexes degrading performance.
171 assert_equal expected, @ui.error