diff options
author | Bundlerbot <bot@bundler.io> | 2019-02-28 18:09:13 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2019-02-28 18:09:13 +0000 |
commit | 4820acf3dbea172c6ec4f165b875acbe85f095cd (patch) | |
tree | 67e07c1249f56035f72829800b9cad3a7722f475 | |
parent | 981fa2ba69ca2199dc3676d83ec7c23453340c90 (diff) | |
parent | 280307575c8a6ba550469498fcf1c7a91ae88026 (diff) | |
download | bundler-4820acf3dbea172c6ec4f165b875acbe85f095cd.tar.gz |
Merge #6991
6991: Fix deprecation specs r=deivid-rodriguez a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was the current deprecation specs are broken. Not the deprecations themselves, their specs.
### What was your diagnosis of the problem?
My diagnosis was we need to fix the specs for the deprecations before actually making sure that the deprecations themselves are properly enabled.
### What is your fix for the problem, implemented in this PR?
My fix is to:
* Get the target version corrected. Deprecation specs should run on bundler 2, not on bundler 1, since deprecations are disabled on bundler 1.
* Get the deprecation matcher fixed. The previous version was passing every time any deprecation was printed and a positive expectation was set. That means that on a spec printing a single deprecation, the assertion `expect(warnings).to have_major_deprecation("bananas will be deprecated in favor of potatoes")`, or any other message, would just pass. This explains why the deprecation specs were currently passing on bundler 1 and it's fixed by https://github.com/bundler/bundler/commit/33383f2faae10cd307b86466921b1a17391bae80.
### Why did you choose this fix out of the possible options?
This fix changes the target for the deprecation specs to bundler 2 (https://github.com/bundler/bundler/commit/e54ddb60298036e3a25c95deda6d575d384ff48a) and uses the following strategy to get CI green after that:
* If the deprecation is already correct on bundler 2, do nothing, the specs already pass.
* If the deprecation is incorrect on bundler 2, but the fix is a no-brainer, fix it here. For example, the `bundle update --all` deprecation (968fe965c), or the `bundle console` deprecation (5bece2f0f).
* If the deprecation is incorrect on bundler 2, but fixing it requires a separate discussion, skip the spec for now, and stage the fix for a separate PR.
I chose this fix because it keeps this PR simple and focused, while unblocking fixing the rest of the deprecations by at least having correct (although disabled) specs for them.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
-rw-r--r-- | lib/bundler/feature_flag.rb | 4 | ||||
-rw-r--r-- | spec/install/gemfile/sources_spec.rb | 62 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 45 | ||||
-rw-r--r-- | spec/support/matchers.rb | 3 |
4 files changed, 69 insertions, 45 deletions
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 0adbd9190f..e98ed8dabf 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -33,7 +33,7 @@ module Bundler settings_flag(:auto_config_jobs) { bundler_2_mode? } settings_flag(:cache_all) { bundler_2_mode? } settings_flag(:cache_command_is_package) { bundler_2_mode? } - settings_flag(:console_command) { !bundler_2_mode? } + settings_flag(:console_command) { !bundler_3_mode? } settings_flag(:default_install_uses_path) { bundler_2_mode? } settings_flag(:deployment_means_frozen) { bundler_2_mode? } settings_flag(:disable_multisource) { bundler_2_mode? } @@ -54,7 +54,7 @@ module Bundler settings_flag(:specific_platform) { bundler_2_mode? } settings_flag(:suppress_install_using_messages) { bundler_2_mode? } settings_flag(:unlock_source_unlocks_spec) { !bundler_2_mode? } - settings_flag(:update_requires_all_flag) { bundler_2_mode? } + settings_flag(:update_requires_all_flag) { bundler_3_mode? } settings_flag(:use_gem_version_promoter_for_major_updates) { bundler_2_mode? } settings_flag(:viz_command) { !bundler_2_mode? } diff --git a/spec/install/gemfile/sources_spec.rb b/spec/install/gemfile/sources_spec.rb index c8f46e48c8..f9e5d072bf 100644 --- a/spec/install/gemfile/sources_spec.rb +++ b/spec/install/gemfile/sources_spec.rb @@ -15,7 +15,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end end - context "with multiple toplevel sources" do + context "with multiple toplevel sources", :bundler => "< 2" do let(:repo3_rack_version) { "1.0.0" } before do @@ -27,12 +27,17 @@ RSpec.describe "bundle install with gems on multiple sources" do G end - it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first", :bundler => "< 2" do + xit "shows a deprecation" do bundle :install - expect(out).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") - expect(out).to include("Warning: the gem 'rack' was found in multiple sources.") - expect(out).to include(normalize_uri_file("Installed from: file://localhost#{gem_repo1}")) + expect(err).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") + end + + it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first" do + bundle :install + + expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include(normalize_uri_file("Installed from: file://localhost#{gem_repo1}")) expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0", :source => "remote1") end @@ -44,7 +49,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end end - context "when different versions of the same gem are in multiple sources" do + context "when different versions of the same gem are in multiple sources", :bundler => "< 2" do let(:repo3_rack_version) { "1.2" } before do @@ -54,14 +59,17 @@ RSpec.describe "bundle install with gems on multiple sources" do gem "rack-obama" gem "rack", "1.0.0" # force it to install the working version in repo1 G - end - it "warns about ambiguous gems, but installs anyway", :bundler => "< 2" do bundle :install + end + + xit "shows a deprecation" do + expect(err).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") + end - expect(out).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") - expect(out).to include("Warning: the gem 'rack' was found in multiple sources.") - expect(out).to include(normalize_uri_file("Installed from: file://localhost#{gem_repo1}")) + it "warns about ambiguous gems, but installs anyway" do + expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include(normalize_uri_file("Installed from: file://localhost#{gem_repo1}")) expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0", :source => "remote1") end end @@ -235,7 +243,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end end - context "and in yet another source" do + context "and in yet another source", :bundler => "< 2" do before do gemfile <<-G source "file://localhost#{gem_repo1}" @@ -244,18 +252,22 @@ RSpec.describe "bundle install with gems on multiple sources" do gem "depends_on_rack" end G - end - it "installs from the other source and warns about ambiguous gems", :bundler => "< 2" do bundle :install - expect(out).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") - expect(out).to include("Warning: the gem 'rack' was found in multiple sources.") - expect(out).to include(normalize_uri_file("Installed from: file://localhost#{gem_repo2}")) + end + + xit "shows a deprecation" do + expect(err).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") + end + + it "installs from the other source and warns about ambiguous gems" do + expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include(normalize_uri_file("Installed from: file://localhost#{gem_repo2}")) expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") end end - context "and only the dependency is pinned" do + context "and only the dependency is pinned", :bundler => "< 2" do before do # need this to be broken to check for correct source ordering build_repo gem_repo2 do @@ -273,10 +285,10 @@ RSpec.describe "bundle install with gems on multiple sources" do G end - it "installs the dependency from the pinned source without warning", :bundler => "< 2" do + it "installs the dependency from the pinned source without warning" do bundle :install - expect(out).not_to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") # In https://github.com/bundler/bundler/issues/3585 this failed @@ -284,7 +296,7 @@ RSpec.describe "bundle install with gems on multiple sources" do system_gems [] bundle :install - expect(out).not_to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") end end @@ -329,7 +341,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "installs all gems without warning" do bundle :install - expect(out).not_to include("Warning") + expect(err).not_to include("Warning") expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", "unrelated_gem 1.0.0") end end @@ -364,7 +376,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "installs the dependency from the top-level source without warning" do bundle :install - expect(out).not_to include("Warning") + expect(err).not_to include("Warning") expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", "unrelated_gem 1.0.0") end end @@ -453,7 +465,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "installs the gems without any warning" do bundle :install - expect(out).not_to include("Warning") + expect(err).not_to include("Warning") expect(the_bundle).to include_gems("rack 1.0.0") end end @@ -631,7 +643,7 @@ RSpec.describe "bundle install with gems on multiple sources" do gem "depends_on_rack" G expect(last_command).to be_failure - expect(last_command.stderr).to eq normalize_uri_file(strip_whitespace(<<-EOS).strip) + expect(err).to eq normalize_uri_file(strip_whitespace(<<-EOS).strip) The gem 'rack' was found in multiple relevant sources. * rubygems repository file://localhost#{gem_repo1}/ or installed locally * rubygems repository file://localhost#{gem_repo4}/ or installed locally diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index ef51112d72..445c970c4c 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true -RSpec.describe "major deprecations", :bundler => "< 2" do - let(:warnings) { last_command.bundler_err } # change to err in 2.0 - let(:warnings_without_version_messages) { warnings.gsub(/#{Spec::Matchers::MAJOR_DEPRECATION}Bundler will only support ruby >= .*/, "") } +RSpec.describe "major deprecations" do + let(:warnings) { err } before do create_file "gems.rb", <<-G @@ -35,29 +34,33 @@ RSpec.describe "major deprecations", :bundler => "< 2" do describe "bundle update --quiet" do it "does not print any deprecations" do bundle :update, :quiet => true - expect(warnings_without_version_messages).not_to have_major_deprecation + expect(warnings).not_to have_major_deprecation end end describe "bundle update" do before do - create_file("gems.rb", "") bundle! "install" end - it "warns when no options are given" do + it "does not warn when no options are given", :bundler => "< 2" do + bundle! "update" + expect(warnings).not_to have_major_deprecation + end + + it "warns when no options are given", :bundler => "2" do bundle! "update" expect(warnings).to have_major_deprecation a_string_including("Pass --all to `bundle update` to update everything") end it "does not warn when --all is passed" do bundle! "update --all" - expect(warnings_without_version_messages).not_to have_major_deprecation + expect(warnings).not_to have_major_deprecation end end describe "bundle install --binstubs" do - it "should output a deprecation warning" do + xit "should output a deprecation warning" do gemfile <<-G gem 'rack' G @@ -76,10 +79,10 @@ RSpec.describe "major deprecations", :bundler => "< 2" do G bundle :install - expect(warnings_without_version_messages).not_to have_major_deprecation + expect(warnings).not_to have_major_deprecation end - it "should print a Gemfile deprecation warning" do + xit "should print a Gemfile deprecation warning" do create_file "gems.rb" install_gemfile! <<-G source "file://#{gem_repo1}" @@ -91,7 +94,7 @@ RSpec.describe "major deprecations", :bundler => "< 2" do end context "with flags" do - it "should print a deprecation warning about autoremembering flags" do + xit "should print a deprecation warning about autoremembering flags" do install_gemfile <<-G, :path => "vendor/bundle" source "file://#{gem_repo1}" gem "rack" @@ -122,7 +125,7 @@ RSpec.describe "major deprecations", :bundler => "< 2" do Bundler.setup RUBY - expect(warnings_without_version_messages).to have_major_deprecation("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") + expect(warnings).to have_major_deprecation("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") end end @@ -139,7 +142,7 @@ RSpec.describe "major deprecations", :bundler => "< 2" do end end - describe Bundler::Dsl do + xdescribe Bundler::Dsl do before do @rubygems = double("rubygems") allow(Bundler::Source::Rubygems).to receive(:new) { @rubygems } @@ -205,24 +208,34 @@ The :bitbucket git source is deprecated, and will be removed in Bundler 2.0. Add end context "bundle show" do - it "prints a deprecation warning" do + before do install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" G bundle! :show + end - warnings.gsub!(/gems included.*?\[DEPRECATED/im, "[DEPRECATED") + it "does not print a deprecation warning", :bundler => "< 2" do + expect(warnings).not_to have_major_deprecation + end + it "prints a deprecation warning", :bundler => "2" do expect(warnings).to have_major_deprecation a_string_including("use `bundle list` instead of `bundle show`") end end context "bundle console" do - it "prints a deprecation warning" do + before do bundle "console" + end + + it "does not print a deprecation warning", :bundler => "< 2" do + expect(warnings).not_to have_major_deprecation + end + it "prints a deprecation warning", :bundler => "2" do expect(warnings).to have_major_deprecation \ a_string_including("bundle console will be replaced by `bin/console` generated by `bundle gem <name>`") end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index c39f2881a6..8f0c1e5f91 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -74,8 +74,7 @@ module Spec match do |actual| deprecations = actual.split(MAJOR_DEPRECATION) - return !expected.nil? if deprecations.size <= 1 - return true if expected.nil? + return !expected.nil? if deprecations.empty? deprecations.any? do |d| !d.empty? && values_match?(expected, d.strip) |