From cb67141f466485b102829d4ae41caaaa43532d62 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 16 May 2026 10:57:14 -0700 Subject: [PATCH] Remove pessimistic versioning in gem command output Switch examples to use `>=2` instead of `~>2.0.0` (which is really terrible as you are limited to 2.0.x versions). For the help output, show a simpler example with a single version restriction, before an example with multiple version restrictions. --- lib/rubygems/commands/fetch_command.rb | 2 +- lib/rubygems/commands/help_command.rb | 4 +++- lib/rubygems/commands/install_command.rb | 2 +- lib/rubygems/commands/uninstall_command.rb | 2 +- test/rubygems/test_gem_commands_fetch_command.rb | 2 +- test/rubygems/test_gem_commands_install_command.rb | 2 +- test/rubygems/test_gem_commands_uninstall_command.rb | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb index c524cf792293..8e64a18cee9a 100644 --- a/lib/rubygems/commands/fetch_command.rb +++ b/lib/rubygems/commands/fetch_command.rb @@ -56,7 +56,7 @@ def check_version # :nodoc: if options[:version] != Gem::Requirement.default && get_all_gem_names.size > 1 alert_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'`" + " version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:>=2'`" terminate_interaction 1 end end diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb index 1619b152e7be..664f400561a4 100644 --- a/lib/rubygems/commands/help_command.rb +++ b/lib/rubygems/commands/help_command.rb @@ -90,7 +90,9 @@ class Gem::Commands::HelpCommand < Gem::Command To depend on a specific set of versions: - gem 'rake', '~> 10.3', '>= 10.3.2' + gem 'rake', '>= 10.3.2' + # or for multiple version restrictions + gem 'rake', '>= 10.3.2', "< 13" RubyGems will require the gem name when activating the gem using the RUBYGEMS_GEMDEPS environment variable or Gem::use_gemdeps. Use the diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 70d32013ba6a..28a2fb7c71de 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -140,7 +140,7 @@ def check_version # :nodoc: if options[:version] != Gem::Requirement.default && get_all_gem_names.size > 1 alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:>=2'`" terminate_interaction 1 end end diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 3d6e41e49e14..3c26074f930c 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -117,7 +117,7 @@ def check_version # :nodoc: if options[:version] != Gem::Requirement.default && get_all_gem_names.size > 1 alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:>=2'`" terminate_interaction 1 end end diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb index 84fad08fd6c6..e673e391fe45 100644 --- a/test/rubygems/test_gem_commands_fetch_command.rb +++ b/test/rubygems/test_gem_commands_fetch_command.rb @@ -157,7 +157,7 @@ def test_execute_two_version execute_with_term_error 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'`" + " version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:>=2'`" assert_empty @ui.output assert_equal msg, @ui.error.chomp diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index d2ca933a632c..cc58d7d105df 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -880,7 +880,7 @@ def test_execute_two_version assert_empty @cmd.installed_specs msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:>=2'`" assert_empty @ui.output assert_equal msg, @ui.error.chomp diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 32553d17300c..71ceb22ce533 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -513,7 +513,7 @@ def test_execute_two_version end msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:>=2'`" assert_empty @ui.output assert_equal msg, @ui.error.lines.last.chomp