diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-03-14 12:05:50 +0100 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-03-14 14:49:09 +0100 |
commit | 79edb8c2cf6bff5ef90d302990bd500ac617149c (patch) | |
tree | 876c6c8cddfc143ca95074afde43c46cc22361c3 | |
parent | b700a8a3e63cf0e926cdc8461320bd3275fd2824 (diff) | |
download | bundler-79edb8c2cf6bff5ef90d302990bd500ac617149c.tar.gz |
Remove the `have_major_deprecation` matcher
With the `have_major_deprecation` matcher as it was, if a command
printed no deprecations, the expectation
```
expect(err).to have_major_deprecation("anything")
```
would actually succeed!
Instead, do something as readable, but simpler.
-rw-r--r-- | spec/install/gemfile/sources_spec.rb | 6 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 40 | ||||
-rw-r--r-- | spec/support/helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/matchers.rb | 13 |
4 files changed, 27 insertions, 36 deletions
diff --git a/spec/install/gemfile/sources_spec.rb b/spec/install/gemfile/sources_spec.rb index f9e5d072bf..2ab1f29de5 100644 --- a/spec/install/gemfile/sources_spec.rb +++ b/spec/install/gemfile/sources_spec.rb @@ -30,7 +30,7 @@ RSpec.describe "bundle install with gems on multiple sources" do xit "shows a deprecation" do bundle :install - expect(err).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") + expect(deprecations).to include("Your Gemfile contains multiple primary sources.") end it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first" do @@ -64,7 +64,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end xit "shows a deprecation" do - expect(err).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") + expect(deprecations).to include("Your Gemfile contains multiple primary sources.") end it "warns about ambiguous gems, but installs anyway" do @@ -257,7 +257,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end xit "shows a deprecation" do - expect(err).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") + expect(deprecations).to include("Your Gemfile contains multiple primary sources.") end it "installs from the other source and warns about ambiguous gems" do diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index 3841ebb626..ab294ad444 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -20,11 +20,11 @@ RSpec.describe "major deprecations" do end it "is not deprecated", :bundler => "< 2" do - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end it "is deprecated in favor of .unbundled_env", :bundler => "2" do - expect(warnings).to have_major_deprecation \ + expect(deprecations).to include \ "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \ "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`" end @@ -37,18 +37,18 @@ RSpec.describe "major deprecations" do end it "is not deprecated", :bundler => "< 2" do - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end it "is deprecated in favor of .load", :bundler => "2" do - expect(warnings).to have_major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + expect(deprecations).to include "Bundler.environment has been removed in favor of Bundler.load" end end describe "bundle update --quiet" do it "does not print any deprecations" do bundle :update, :quiet => true - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end end @@ -59,24 +59,24 @@ RSpec.describe "major deprecations" do it "does not warn when no options are given", :bundler => "< 2" do bundle! "update" - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty 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") + expect(deprecations).to include("Pass --all to `bundle update` to update everything") end it "does not warn when --all is passed" do bundle! "update --all" - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end end describe "bundle install --binstubs" do xit "should output a deprecation warning" do bundle :install, :binstubs => true - expect(warnings).to have_major_deprecation a_string_including("The --binstubs option will be removed") + expect(deprecations).to include("The --binstubs option will be removed") end end end @@ -89,7 +89,7 @@ RSpec.describe "major deprecations" do G bundle :install - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end it "should print a proper warning when both gems.rb and Gemfile present, and use Gemfile", :bundler => "< 2" do @@ -129,7 +129,7 @@ RSpec.describe "major deprecations" do end it "should print a deprecation warning about autoremembering flags", :bundler => "3" do - expect(warnings).to have_major_deprecation a_string_including( + expect(deprecations).to include( "flags passed to commands will no longer be automatically remembered." ) end @@ -152,7 +152,7 @@ RSpec.describe "major deprecations" do it "should print a deprecation warning" do bundle "install #{flag_name} #{value}" - expect(warnings).to have_major_deprecation( + expect(deprecations).to include( "The `#{flag_name}` flag is deprecated because it relied on " \ "being remembered accross bundler invokations, which bundler " \ "will no longer do in future versions. Instead please use " \ @@ -165,7 +165,7 @@ RSpec.describe "major deprecations" do it "should not print a deprecation warning" do bundle "install #{flag_name} #{value}" - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end end end @@ -212,11 +212,11 @@ RSpec.describe "major deprecations" do end it "should not print a capistrano deprecation warning", :bundler => "< 2" do - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty end it "should print a capistrano deprecation warning", :bundler => "2" do - expect(warnings).to have_major_deprecation("Bundler no longer integrates " \ + expect(deprecations).to include("Bundler no longer integrates " \ "with Capistrano, but Capistrano provides " \ "its own integration with Bundler via the " \ "capistrano-bundler gem. Use it instead.") @@ -306,11 +306,11 @@ The :gist git source is deprecated, and will be removed in the future. Add this end it "does not print a deprecation warning", :bundler => "< 2" do - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty 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`") + expect(deprecations).to include("use `bundle list` instead of `bundle show`") end end @@ -320,12 +320,12 @@ The :gist git source is deprecated, and will be removed in the future. Add this end it "does not print a deprecation warning", :bundler => "< 2" do - expect(warnings).not_to have_major_deprecation + expect(deprecations).to be_empty 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>`") + expect(deprecations).to include \ + "bundle console will be replaced by `bin/console` generated by `bundle gem <name>`" end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index b4ea1db78d..151c99c3ff 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -54,6 +54,10 @@ module Spec last_command.stderr.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "") end + def deprecations + err.split("\n").select {|l| l =~ MAJOR_DEPRECATION }.join("\n").split(MAJOR_DEPRECATION) + end + def exitstatus last_command.exitstatus end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 090618c2b5..38de9450fb 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -62,19 +62,6 @@ module Spec MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/.freeze - RSpec::Matchers.define :have_major_deprecation do |expected| - diffable - match do |actual| - deprecations = actual.split(MAJOR_DEPRECATION) - - return !expected.nil? if deprecations.empty? - - deprecations.any? do |d| - !d.empty? && values_match?(expected, d.strip) - end - end - end - RSpec::Matchers.define :have_dep do |*args| dep = Bundler::Dependency.new(*args) |