From ee5e684bc1fda49bc28f0fcfc2f79abb26994f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 6 Jan 2022 14:05:46 +0100 Subject: [rubygems/rubygems] Fix `gem install --force` crash Before: ``` $ gem install sfdsfdsfsdide --force ERROR: While executing gem ... (NoMethodError) undefined method `spec' for nil:NilClass @always_install << newest.spec ^^^^^ ``` After: ``` $ gem install sfdsfdsfsdide --force ERROR: Could not find a valid gem 'sfdsfdsfsdide' (>= 0) in any repository ``` https://github.com/rubygems/rubygems/commit/4e2bfd1101 --- test/rubygems/test_gem_commands_install_command.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 0365b2c408..47a97dae4b 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -277,6 +277,22 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error) end + def test_execute_nonexistent_force + spec_fetcher + + @cmd.options[:args] = %w[nonexistent] + @cmd.options[:force] = true + + use_ui @ui do + e = assert_raise Gem::MockGemUi::TermError do + @cmd.execute + end + assert_equal 2, e.exit_code + end + + assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error) + end + def test_execute_dependency_nonexistent spec_fetcher do |fetcher| fetcher.spec 'foo', 2, 'bar' => '0.5' -- cgit v1.2.3