From 39904ba9e655f5fed28d052f98e21444fdd716d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 28 Feb 2019 17:40:27 +0100 Subject: [PATCH 1/3] Extract setup logic to a before block --- spec/other/major_deprecation_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index 445c970c4ce..8aa60055295 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -108,7 +108,7 @@ end context "when Bundler.setup is run in a ruby script" do - it "should print a single deprecation warning" do + before do create_file "gems.rb" install_gemfile! <<-G source "file://#{gem_repo1}" @@ -124,7 +124,9 @@ Bundler.setup Bundler.setup RUBY + end + it "should print a single deprecation warning" do expect(warnings).to have_major_deprecation("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") end end From 6b6d56111e3360eaf2bececb775ea34492753a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 28 Feb 2019 17:48:47 +0100 Subject: [PATCH 2/3] Lighther "prefer gems.rb" deprecation The previous logic is unclear to me. It seemed to try to detect only "multiple gemfile situations", but it was doing it incorrectly, I think. The new message is printed _only_ if both gems.rb and Gemfile are detected in the same project. And recommends sticking with gems.rb. But we are not yet deprecating "Gemfile" other than that. --- lib/bundler/shared_helpers.rb | 13 +++++++---- spec/other/major_deprecation_spec.rb | 33 ++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 996f7b3fd40..0f4f54dcedf 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -157,11 +157,16 @@ def print_major_deprecations! multiple_gemfiles = search_up(".") do |dir| gemfiles = gemfile_names.select {|gf| File.file? File.expand_path(gf, dir) } next if gemfiles.empty? - break false if gemfiles.size == 1 + break gemfiles.size != 1 end - return unless multiple_gemfiles && Bundler.bundler_major_version == 1 - Bundler::SharedHelpers.major_deprecation 2, \ - "gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock." + return unless multiple_gemfiles + diagnosis = "Multiple gemfiles (gems.rb and Gemfile) detected." + advice = if Bundler.feature_flag.prefer_gems_rb? + "Make sure you remove Gemfile and Gemfile.lock since bundler is ignoring them in favor of gems.rb and gems.rb.locked." + else + "The gems.rb and gems.rb.locked files are currently ignored, but they will get used as soon as you delete your Gemfile and Gemfile.lock files." + end + Bundler.ui.warn [diagnosis, advice].join(" ") end def trap(signal, override = false, &block) diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index 8aa60055295..ae9253fef56 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -82,15 +82,32 @@ expect(warnings).not_to have_major_deprecation end - xit "should print a Gemfile deprecation warning" do + it "should print a proper warning when both gems.rb and Gemfile present, and use Gemfile", :bundler => "< 2" do create_file "gems.rb" install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" G + + expect(warnings).to include( + "Multiple gemfiles (gems.rb and Gemfile) detected. The gems.rb and gems.rb.locked files are currently ignored, but they will get used as soon as you delete your Gemfile and Gemfile.lock files." + ) + expect(the_bundle).to include_gem "rack 1.0" + end + + it "should print a proper warning when both gems.rb and Gemfile present, and use gems.rb", :bundler => "2" do + create_file "gems.rb" + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rack" + G - expect(warnings).to have_major_deprecation a_string_including("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") + expect(warnings).to include( + "Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler is ignoring them in favor of gems.rb and gems.rb.locked." + ) + + expect(the_bundle).not_to include_gem "rack 1.0" end context "with flags" do @@ -126,8 +143,16 @@ RUBY end - it "should print a single deprecation warning" do - expect(warnings).to have_major_deprecation("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") + it "should print a single deprecation warning", :bundler => "< 2" do + expect(warnings).to include( + "Multiple gemfiles (gems.rb and Gemfile) detected. The gems.rb and gems.rb.locked files are currently ignored, but they will get used as soon as you delete your Gemfile and Gemfile.lock files." + ) + end + + it "should print a single deprecation warning", :bundler => "2" do + expect(warnings).to include( + "Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler is ignoring them in favor of gems.rb and gems.rb.locked." + ) end end From c1df6bc042009873cf669df643aa4d0f37358c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 21 Feb 2019 18:09:24 +0100 Subject: [PATCH 3/3] Better test description --- spec/other/major_deprecation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index ae9253fef56..550808103f6 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -71,7 +71,7 @@ end end - context "when bundle is run" do + context "when bundle install is run" do it "should not warn about gems.rb" do create_file "gems.rb", <<-G source "file://#{gem_repo1}"