File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ def -(other)
178178 end
179179
180180 def find_by_name_and_platform ( name , platform )
181- @specs . detect { |spec | spec . name == name && spec . installable_on_platform? ( platform ) }
181+ lookup [ name ] & .detect { |spec | spec . installable_on_platform? ( platform ) }
182182 end
183183
184184 def specs_with_additional_variants_from ( other )
@@ -314,7 +314,7 @@ def valid_dependencies?(s)
314314 end
315315
316316 def sorted
317- @sorted ||= ( [ @specs . find { | s | s . name == "rake" } ] + tsort ) . compact . uniq
317+ @sorted ||= ( [ lookup [ "rake" ] &. first ] + tsort ) . compact . uniq
318318 rescue TSort ::Cyclic => error
319319 cgems = extract_circular_gems ( error )
320320 raise CyclicDependencyError , "Your bundle requires gems that depend" \
Original file line number Diff line number Diff line change 4343 spec = described_class . new ( specs ) . find_by_name_and_platform ( "b" , platform )
4444 expect ( spec ) . to eq platform_spec
4545 end
46+
47+ it "returns nil when the name is not present" do
48+ spec = described_class . new ( specs ) . find_by_name_and_platform ( "missing" , platform )
49+ expect ( spec ) . to be_nil
50+ end
51+
52+ it "returns nil when the name exists but no spec is installable on the requested platform" do
53+ incompatible_platform = Gem ::Platform . new ( "java" )
54+ incompatible_spec = build_spec ( "a" , "1.0" , incompatible_platform ) . first
55+
56+ spec = described_class . new ( [ incompatible_spec ] ) . find_by_name_and_platform ( "a" , platform )
57+ expect ( spec ) . to be_nil
58+ end
59+
60+ it "returns the first installable spec for the given name in insertion order" do
61+ later_platform_spec = build_spec ( "b" , "3.0" , platform ) . first
62+ specs = [
63+ platform_spec ,
64+ later_platform_spec ,
65+ ]
66+
67+ spec = described_class . new ( specs ) . find_by_name_and_platform ( "b" , platform )
68+ expect ( spec ) . to eq platform_spec
69+ end
4670 end
4771
4872 describe "#to_a" do
5579 d-2.0
5680 ]
5781 end
82+
83+ it "puts rake first when present" do
84+ specs = [
85+ build_spec ( "a" , "1.0" ) { |s | s . dep "rake" , ">= 0" } ,
86+ build_spec ( "rake" , "13.0" ) ,
87+ ] . flatten
88+
89+ expect ( described_class . new ( specs ) . to_a . map ( &:full_name ) ) . to eq %w[
90+ rake-13.0
91+ a-1.0
92+ ]
93+ end
5894 end
5995end
You can’t perform that action at this time.
0 commit comments