summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_commands_fetch_command.rb
diff options
context:
space:
mode:
authorximenasandoval <ximena.sandoval.dh@gmail.com>2021-12-29 14:24:04 -0700
committergit <svn-admin@ruby-lang.org>2022-01-06 23:58:38 +0900
commitcea4a81056311f13ca1c17f26c9d2c21b5a017a6 (patch)
treed8cdf026308c98bed4902a2a1a1ba7af12a0735d /test/rubygems/test_gem_commands_fetch_command.rb
parentee5e684bc1fda49bc28f0fcfc2f79abb26994f08 (diff)
[rubygems/rubygems] Let fetch understand gem:version syntax
Fix version error message Add tests to fetch error messages Fix default version since is not necessary https://github.com/rubygems/rubygems/commit/070620ebe4
Diffstat (limited to 'test/rubygems/test_gem_commands_fetch_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb97
1 files changed, 97 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb
index c745648d56..550c05b998 100644
--- a/test/rubygems/test_gem_commands_fetch_command.rb
+++ b/test/rubygems/test_gem_commands_fetch_command.rb
@@ -157,4 +157,101 @@ class TestGemCommandsFetchCommand < Gem::TestCase
assert_path_exist(File.join(@tempdir, a1.file_name),
"#{a1.full_name} not fetched")
end
+
+ def test_execute_version_specified_by_colon
+ specs = spec_fetcher do |fetcher|
+ fetcher.gem 'a', 1
+ end
+
+ @cmd.options[:args] = %w[a:1]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ a1 = specs['a-1']
+
+ assert_path_exist(File.join(@tempdir, a1.file_name),
+ "#{a1.full_name} not fetched")
+ end
+
+ def test_execute_two_version
+ @cmd.options[:args] = %w[a b]
+ @cmd.options[:version] = Gem::Requirement.new '1'
+
+ use_ui @ui do
+ assert_raise Gem::MockGemUi::TermError, @ui.error do
+ @cmd.execute
+ end
+ end
+
+ msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \
+ " version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`"
+
+ assert_empty @ui.output
+ assert_equal msg, @ui.error.chomp
+ end
+
+ def test_execute_two_version_specified_by_colon
+ specs = spec_fetcher do |fetcher|
+ fetcher.gem 'a', 1
+ fetcher.gem 'b', 1
+ end
+
+ @cmd.options[:args] = %w[a:1 b:1]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ a1 = specs['a-1']
+ b1 = specs['b-1']
+
+ assert_path_exist(File.join(@tempdir, a1.file_name),
+ "#{a1.full_name} not fetched")
+ assert_path_exist(File.join(@tempdir, b1.file_name),
+ "#{b1.full_name} not fetched")
+ end
+
+ def test_execute_version_nonexistent
+ spec_fetcher do |fetcher|
+ fetcher.spec 'foo', 1
+ end
+
+ @cmd.options[:args] = %w[foo:2]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EXPECTED
+ERROR: Could not find a valid gem 'foo' (2) in any repository
+ERROR: Possible alternatives: foo
+ EXPECTED
+
+ assert_equal expected, @ui.error
+ end
+
+ def test_execute_nonexistent_hint_disabled
+ spec_fetcher do |fetcher|
+ fetcher.spec 'foo', 1
+ end
+
+ @cmd.options[:args] = %w[foo:2]
+ @cmd.options[:suggest_alternate] = true
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EXPECTED
+ERROR: Could not find a valid gem 'foo' (2) in any repository
+ EXPECTED
+
+ assert_equal expected, @ui.error
+ end
end