mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Fix gem install <non-existent-gem> --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
```
4e2bfd1101
This commit is contained in:
parent
e3b0c8c106
commit
ee5e684bc1
2 changed files with 25 additions and 9 deletions
|
@ -76,21 +76,21 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
|
||||||
|
|
||||||
newest = found.last
|
newest = found.last
|
||||||
|
|
||||||
|
unless newest
|
||||||
|
exc = Gem::UnsatisfiableDependencyError.new request
|
||||||
|
exc.errors = errors
|
||||||
|
|
||||||
|
raise exc
|
||||||
|
end
|
||||||
|
|
||||||
unless @force
|
unless @force
|
||||||
found_matching_metadata = found.reverse.find do |spec|
|
found_matching_metadata = found.reverse.find do |spec|
|
||||||
metadata_satisfied?(spec)
|
metadata_satisfied?(spec)
|
||||||
end
|
end
|
||||||
|
|
||||||
if found_matching_metadata.nil?
|
if found_matching_metadata.nil?
|
||||||
if newest
|
ensure_required_ruby_version_met(newest.spec)
|
||||||
ensure_required_ruby_version_met(newest.spec)
|
ensure_required_rubygems_version_met(newest.spec)
|
||||||
ensure_required_rubygems_version_met(newest.spec)
|
|
||||||
else
|
|
||||||
exc = Gem::UnsatisfiableDependencyError.new request
|
|
||||||
exc.errors = errors
|
|
||||||
|
|
||||||
raise exc
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
newest = found_matching_metadata
|
newest = found_matching_metadata
|
||||||
end
|
end
|
||||||
|
|
|
@ -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)
|
assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error)
|
||||||
end
|
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
|
def test_execute_dependency_nonexistent
|
||||||
spec_fetcher do |fetcher|
|
spec_fetcher do |fetcher|
|
||||||
fetcher.spec 'foo', 2, 'bar' => '0.5'
|
fetcher.spec 'foo', 2, 'bar' => '0.5'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue