Skip to content

Commit 335f90b

Browse files
homusegiddins
authored andcommitted
Auto merge of #1910 - rubygems:seg-finish-resolve-respects-activated, r=indirect
Allow Gem.finish_resolve to respect already-activated specs # Description: Previously, if a gem was already activated, `finish_resolve` wouldn't consider the activated dependency as a requirement, always leading to a hard error. This makes finish_resolve work as you'd respect. # Tasks: - [x] Describe the problem / feature - [x] Write tests - [x] Write code to solve the problem - [ ] Get code review from coworkers / friends I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md). (cherry picked from commit fd24f01)
1 parent 2502ab2 commit 335f90b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/rubygems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def self.needs
234234

235235
def self.finish_resolve(request_set=Gem::RequestSet.new)
236236
request_set.import Gem::Specification.unresolved_deps.values
237+
request_set.import Gem.loaded_specs.values.map {|s| Gem::Dependency.new(s.name, s.version) }
237238

238239
request_set.resolve_current.each do |s|
239240
s.full_spec.activate

lib/rubygems/test_case.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,8 @@ def self.key_path key_name
14981498
begin
14991499
gem 'rdoc'
15001500
require 'rdoc'
1501+
1502+
require 'rubygems/rdoc'
15011503
rescue LoadError, Gem::LoadError
15021504
end
15031505

@@ -1514,3 +1516,4 @@ def self.key_path key_name
15141516
pid = $$
15151517
END {tmpdirs.each {|dir| Dir.rmdir(dir)} if $$ == pid}
15161518
Gem.clear_paths
1519+
Gem.loaded_specs.clear

test/rubygems/test_gem.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ def test_self_finish_resolve_wtf
7575
end
7676
end
7777

78+
def test_self_finish_resolve_respects_loaded_specs
79+
save_loaded_features do
80+
a1 = new_spec "a", "1", "b" => "> 0"
81+
b1 = new_spec "b", "1", "c" => ">= 1"
82+
b2 = new_spec "b", "2", "c" => ">= 2"
83+
c1 = new_spec "c", "1"
84+
c2 = new_spec "c", "2"
85+
86+
install_specs c1, c2, b1, b2, a1
87+
88+
a1.activate
89+
c1.activate
90+
91+
assert_equal %w(a-1 c-1), loaded_spec_names
92+
assert_equal ["b (> 0)"], unresolved_names
93+
94+
Gem.finish_resolve
95+
96+
assert_equal %w(a-1 b-1 c-1), loaded_spec_names
97+
assert_equal [], unresolved_names
98+
end
99+
end
100+
78101
def test_self_install
79102
spec_fetcher do |f|
80103
f.gem 'a', 1

0 commit comments

Comments
 (0)