Skip to content

Commit 6e35a6e

Browse files
Preserve the previous behavior of raising an error when in frozen mode
1 parent 7b0f780 commit 6e35a6e

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

bundler/lib/bundler/lazy_specification.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ def __materialize__(candidates)
108108
(spec.required_ruby_version.satisfied_by?(Gem.ruby_version) &&
109109
spec.required_rubygems_version.satisfied_by?(Gem.rubygems_version))
110110
end
111-
search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification))
111+
if search.nil? && Bundler.frozen_bundle?
112+
search = candidates.last
113+
else
114+
search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification))
115+
end
112116
search
113117
end
114118
end

bundler/spec/install/gems/resolving_spec.rb

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -241,55 +241,68 @@
241241
expect(the_bundle).to include_gems("rack 1.2")
242242
end
243243

244-
it "automatically updates lockfile to use the older version" do
245-
build_repo2 do
246-
build_gem "parallel_tests", "3.7.0" do |s|
247-
s.required_ruby_version = ">= #{current_ruby_minor}"
248-
end
244+
context "when there is a lockfile using the newer incompatible version" do
245+
before do
246+
build_repo2 do
247+
build_gem "parallel_tests", "3.7.0" do |s|
248+
s.required_ruby_version = ">= #{current_ruby_minor}"
249+
end
249250

250-
build_gem "parallel_tests", "3.8.0" do |s|
251-
s.required_ruby_version = ">= #{next_ruby_minor}"
251+
build_gem "parallel_tests", "3.8.0" do |s|
252+
s.required_ruby_version = ">= #{next_ruby_minor}"
253+
end
252254
end
253-
end
254255

255-
gemfile <<-G
256-
source "http://localgemserver.test/"
257-
gem 'parallel_tests'
258-
G
256+
gemfile <<-G
257+
source "http://localgemserver.test/"
258+
gem 'parallel_tests'
259+
G
259260

260-
lockfile <<~L
261-
GEM
262-
remote: http://localgemserver.test/
263-
specs:
264-
parallel_tests (3.8.0)
261+
lockfile <<~L
262+
GEM
263+
remote: http://localgemserver.test/
264+
specs:
265+
parallel_tests (3.8.0)
265266
266-
PLATFORMS
267-
#{lockfile_platforms}
267+
PLATFORMS
268+
#{lockfile_platforms}
268269
269-
DEPENDENCIES
270-
parallel_tests
270+
DEPENDENCIES
271+
parallel_tests
271272
272-
BUNDLED WITH
273-
#{Bundler::VERSION}
274-
L
273+
BUNDLED WITH
274+
#{Bundler::VERSION}
275+
L
276+
end
275277

276-
bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
278+
it "automatically updates lockfile to use the older version" do
279+
bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
277280

278-
expect(lockfile).to eq <<~L
279-
GEM
280-
remote: http://localgemserver.test/
281-
specs:
282-
parallel_tests (3.7.0)
281+
expect(lockfile).to eq <<~L
282+
GEM
283+
remote: http://localgemserver.test/
284+
specs:
285+
parallel_tests (3.7.0)
283286
284-
PLATFORMS
285-
#{lockfile_platforms}
287+
PLATFORMS
288+
#{lockfile_platforms}
286289
287-
DEPENDENCIES
288-
parallel_tests
290+
DEPENDENCIES
291+
parallel_tests
289292
290-
BUNDLED WITH
291-
#{Bundler::VERSION}
292-
L
293+
BUNDLED WITH
294+
#{Bundler::VERSION}
295+
L
296+
end
297+
298+
it "gives a meaningful error if we're in frozen mode" do
299+
expect do
300+
bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s, "BUNDLE_FROZEN" => "true" }, :raise_on_error => false
301+
end.not_to change { lockfile }
302+
303+
expect(err).to include("parallel_tests-3.8.0 requires ruby version >= #{next_ruby_minor}")
304+
expect(err).not_to include("That means the author of parallel_tests (3.8.0) has removed it.")
305+
end
293306
end
294307

295308
it "gives a meaningful error on ruby version mismatches between dependencies" do

0 commit comments

Comments
 (0)