From 59652415cfe26353633eb415514f3fd39d443237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 12 Mar 2019 18:03:44 +0100 Subject: Make deprecation specs less messy --- spec/other/major_deprecation_spec.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index de9c05ec67..fabf6321d1 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -3,16 +3,16 @@ RSpec.describe "major deprecations" do let(:warnings) { err } - before do - create_file "gems.rb", <<-G - source "file:#{gem_repo1}" - ruby #{RUBY_VERSION.dump} - gem "rack" - G - bundle! "install" - end - describe "Bundler" do + before do + create_file "gems.rb", <<-G + source "file:#{gem_repo1}" + ruby #{RUBY_VERSION.dump} + gem "rack" + G + bundle! "install" + end + describe ".clean_env" do it "is deprecated in favor of .unbundled_env" do source = "Bundler.clean_env" @@ -61,10 +61,6 @@ RSpec.describe "major deprecations" do describe "bundle install --binstubs" do xit "should output a deprecation warning" do - gemfile <<-G - gem 'rack' - G - bundle :install, :binstubs => true expect(warnings).to have_major_deprecation a_string_including("The --binstubs option will be removed") end @@ -111,12 +107,14 @@ RSpec.describe "major deprecations" do end context "with flags" do - it "should print a deprecation warning about autoremembering flags", :bundler => "3" do + before do install_gemfile <<-G, :path => "vendor/bundle" source "file://#{gem_repo1}" gem "rack" G + end + it "should print a deprecation warning about autoremembering flags", :bundler => "3" do expect(warnings).to have_major_deprecation a_string_including( "flags passed to commands will no longer be automatically remembered." ) -- cgit v1.2.1 From a87cdf6ffdc31a51db6f1598de294c5a261d7d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 13:29:11 +0100 Subject: Fix broken deprecation specs These specs were only passing on bundler 2 because the matcher is buggy. Now they are correct. --- spec/other/major_deprecation_spec.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index fabf6321d1..3841ebb626 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -14,9 +14,16 @@ RSpec.describe "major deprecations" do end describe ".clean_env" do - it "is deprecated in favor of .unbundled_env" do + before do source = "Bundler.clean_env" bundle "exec ruby -e #{source.dump}" + end + + it "is not deprecated", :bundler => "< 2" do + expect(warnings).not_to have_major_deprecation + end + + it "is deprecated in favor of .unbundled_env", :bundler => "2" do expect(warnings).to have_major_deprecation \ "`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`" @@ -24,9 +31,16 @@ RSpec.describe "major deprecations" do end describe ".environment" do - it "is deprecated in favor of .load" do + before do source = "Bundler.environment" bundle "exec ruby -e #{source.dump}" + end + + it "is not deprecated", :bundler => "< 2" do + expect(warnings).not_to have_major_deprecation + 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" end end @@ -191,11 +205,17 @@ RSpec.describe "major deprecations" do end context "when `bundler/deployment` is required in a ruby script" do - it "should print a capistrano deprecation warning" do + before do ruby(<<-RUBY) require 'bundler/deployment' RUBY + end + + it "should not print a capistrano deprecation warning", :bundler => "< 2" do + expect(warnings).not_to have_major_deprecation + end + it "should print a capistrano deprecation warning", :bundler => "2" do expect(warnings).to have_major_deprecation("Bundler no longer integrates " \ "with Capistrano, but Capistrano provides " \ "its own integration with Bundler via the " \ -- cgit v1.2.1 From b700a8a3e63cf0e926cdc8461320bd3275fd2824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 13:43:52 +0100 Subject: Remove `eq_err` matcher In favor of a simpler helper. --- spec/commands/show_spec.rb | 2 +- spec/install/gemfile/git_spec.rb | 4 ++-- spec/install/gemfile/groups_spec.rb | 6 +++--- spec/install/gemfile/path_spec.rb | 4 ++-- spec/runtime/require_spec.rb | 12 ++++++------ spec/support/helpers.rb | 6 ++++++ spec/support/matchers.rb | 7 ------- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb index 8e3d0194e6..298618747f 100644 --- a/spec/commands/show_spec.rb +++ b/spec/commands/show_spec.rb @@ -157,7 +157,7 @@ RSpec.describe "bundle show" do it "does not output git errors" do bundle :show - expect(last_command.stderr).to eq_err("") + expect(err_without_deprecations).to be_empty end end diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index cac571754c..2cb6c7485f 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -1067,7 +1067,7 @@ RSpec.describe "bundle install with git sources" do bundle :install, :requires => [lib_path("install_hooks.rb")] - expect(last_command.stderr).to eq_err("Ran pre-install hook: foo-1.0") + expect(err_without_deprecations).to eq("Ran pre-install hook: foo-1.0") end it "runs post-install hooks" do @@ -1087,7 +1087,7 @@ RSpec.describe "bundle install with git sources" do bundle :install, :requires => [lib_path("install_hooks.rb")] - expect(last_command.stderr).to eq_err("Ran post-install hook: foo-1.0") + expect(err_without_deprecations).to eq("Ran post-install hook: foo-1.0") end it "complains if the install hook fails" do diff --git a/spec/install/gemfile/groups_spec.rb b/spec/install/gemfile/groups_spec.rb index 1b739e18ce..2787172057 100644 --- a/spec/install/gemfile/groups_spec.rb +++ b/spec/install/gemfile/groups_spec.rb @@ -25,7 +25,7 @@ RSpec.describe "bundle install with groups" do puts ACTIVESUPPORT R - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end it "installs gems with inline :groups into those groups" do @@ -36,7 +36,7 @@ RSpec.describe "bundle install with groups" do puts THIN R - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end it "sets up everything if Bundler.setup is used with no groups" do @@ -57,7 +57,7 @@ RSpec.describe "bundle install with groups" do puts THIN RUBY - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end it "sets up old groups when they have previously been removed" do diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb index 224c28269e..40c137cd4a 100644 --- a/spec/install/gemfile/path_spec.rb +++ b/spec/install/gemfile/path_spec.rb @@ -575,7 +575,7 @@ RSpec.describe "bundle install with explicit source paths" do bundle :install, :requires => [lib_path("install_hooks.rb")] - expect(last_command.stderr).to eq_err("Ran pre-install hook: foo-1.0") + expect(err_without_deprecations).to eq("Ran pre-install hook: foo-1.0") end it "runs post-install hooks" do @@ -595,7 +595,7 @@ RSpec.describe "bundle install with explicit source paths" do bundle :install, :requires => [lib_path("install_hooks.rb")] - expect(last_command.stderr).to eq_err("Ran post-install hook: foo-1.0") + expect(err_without_deprecations).to eq("Ran post-install hook: foo-1.0") end it "complains if the install hook fails" do diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 7a32fc6117..c9cfa199d3 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/runtime/require_spec.rb @@ -121,7 +121,7 @@ RSpec.describe "Bundler.require" do Bundler.require R - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end it "displays a helpful message if the required gem throws an error" do @@ -160,7 +160,7 @@ RSpec.describe "Bundler.require" do RUBY run(cmd) - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR: cannot load such file -- load-bar") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar") end describe "with namespaced gems" do @@ -211,7 +211,7 @@ RSpec.describe "Bundler.require" do load_error_run <<-R, "jquery-rails" Bundler.require R - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end it "handles the case where regex fails" do @@ -234,7 +234,7 @@ RSpec.describe "Bundler.require" do RUBY run(cmd) - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end it "doesn't swallow the error when the library has an unrelated error" do @@ -258,7 +258,7 @@ RSpec.describe "Bundler.require" do RUBY run(cmd) - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR: cannot load such file -- load-bar") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar") end end @@ -366,7 +366,7 @@ RSpec.describe "Bundler.require" do load_error_run <<-R, "no_such_file_omg" Bundler.require R - expect(last_command.stderr).to eq_err("ZOMG LOAD ERROR") + expect(err_without_deprecations).to eq("ZOMG LOAD ERROR") end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index a5ff292f01..b4ea1db78d 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -48,6 +48,12 @@ module Spec Bundler.feature_flag.error_on_stderr? ? last_command.stderr : last_command.stdout end + MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/.freeze + + def err_without_deprecations + last_command.stderr.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "") + end + def exitstatus last_command.exitstatus end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 2e2c51edfa..090618c2b5 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -62,13 +62,6 @@ module Spec MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/.freeze - RSpec::Matchers.define :eq_err do |expected| - diffable - match do |actual| - actual.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "") == expected - end - end - RSpec::Matchers.define :have_major_deprecation do |expected| diffable match do |actual| -- cgit v1.2.1 From 79edb8c2cf6bff5ef90d302990bd500ac617149c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 12:05:50 +0100 Subject: 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. --- spec/install/gemfile/sources_spec.rb | 6 +++--- spec/other/major_deprecation_spec.rb | 40 ++++++++++++++++++------------------ spec/support/helpers.rb | 4 ++++ 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 `") + expect(deprecations).to include \ + "bundle console will be replaced by `bin/console` generated by `bundle gem `" 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) -- cgit v1.2.1 From 99d55c01577519b4bc6ca9565685eb8d3f8069f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 14:04:30 +0100 Subject: Be agressive, our specs should print no deprecations --- spec/support/matchers.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 38de9450fb..0a9285837a 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -60,8 +60,6 @@ module Spec end end - MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/.freeze - RSpec::Matchers.define :have_dep do |*args| dep = Bundler::Dependency.new(*args) @@ -135,7 +133,6 @@ module Spec rescue StandardError => e next "#{name} is not installed:\n#{indent(e)}" end - last_command.stdout.gsub!(/#{MAJOR_DEPRECATION}.*$/, "") actual_version, actual_platform = last_command.stdout.strip.split(/\s+/, 2) unless Gem::Version.new(actual_version) == Gem::Version.new(version) next "#{name} was expected to be at version #{version} but was #{actual_version}" @@ -150,7 +147,6 @@ module Spec rescue StandardError next "#{name} does not have a source defined:\n#{indent(e)}" end - last_command.stdout.gsub!(/#{MAJOR_DEPRECATION}.*$/, "") unless last_command.stdout.strip == source next "Expected #{name} (#{version}) to be installed from `#{source}`, was actually from `#{out}`" end -- cgit v1.2.1