diff options
Diffstat (limited to 'spec/bundler/install/gemfile/sources_spec.rb')
-rw-r--r-- | spec/bundler/install/gemfile/sources_spec.rb | 147 |
1 files changed, 107 insertions, 40 deletions
diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index efe6ccce7f..8e1205dfa3 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/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 => "< 3" do let(:repo3_rack_version) { "1.0.0" } before do @@ -25,27 +25,24 @@ RSpec.describe "bundle install with gems on multiple sources" do gem "rack-obama" gem "rack" G - bundle "config major_deprecations true" end - it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first", :bundler => "< 3" do + it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first", :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_repo1}")) + 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 - it "errors when disable_multisource is set" do - bundle "config disable_multisource true" + it "fails", :bundler => "3" do bundle :install - expect(out).to include("Each source after the first must include a block") + expect(err).to include("Each source after the first must include a block") expect(exitstatus).to eq(4) if exitstatus 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 => "< 3" do let(:repo3_rack_version) { "1.2" } before do @@ -55,17 +52,20 @@ 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 - bundle "config major_deprecations true" - end - it "warns about ambiguous gems, but installs anyway", :bundler => "< 3" do bundle :install + 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", :bundler => "2" 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 + + it "fails", :bundler => "3" do + expect(err).to include("Each source after the first must include a block") + expect(exitstatus).to eq(4) if exitstatus + end end end @@ -187,10 +187,9 @@ RSpec.describe "bundle install with gems on multiple sources" do end end - context "when lockfile_uses_separate_rubygems_sources is set" do + context "when disable_multisource is set" do before do - bundle! "config lockfile_uses_separate_rubygems_sources true" - bundle! "config disable_multisource true" + bundle! "config set disable_multisource true" end it "installs from the same source without any warning" do @@ -237,7 +236,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 => "< 3" do before do gemfile <<-G source "file://localhost#{gem_repo1}" @@ -246,19 +245,23 @@ 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 => "< 3" do - bundle "config major_deprecations true" 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 + + it "installs from the other source and warns about ambiguous gems", :bundler => "2" 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 + + it "fails", :bundler => "3" do + expect(err).to include("Each source after the first must include a block") + expect(exitstatus).to eq(4) if exitstatus + end end - context "and only the dependency is pinned" do + context "and only the dependency is pinned", :bundler => "< 3" do before do # need this to be broken to check for correct source ordering build_repo gem_repo2 do @@ -276,10 +279,10 @@ RSpec.describe "bundle install with gems on multiple sources" do G end - it "installs the dependency from the pinned source without warning", :bundler => "< 3" do + it "installs the dependency from the pinned source without warning", :bundler => "2" 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 @@ -287,18 +290,23 @@ 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 + + it "fails", :bundler => "3" do + bundle :install + expect(err).to include("Each source after the first must include a block") + expect(exitstatus).to eq(4) if exitstatus + end end end end context "when a top-level gem has an indirect dependency" do - context "when lockfile_uses_separate_rubygems_sources is set" do + context "when disable_multisource is set" do before do - bundle! "config lockfile_uses_separate_rubygems_sources true" - bundle! "config disable_multisource true" + bundle! "config set disable_multisource true" end before do @@ -332,7 +340,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 @@ -348,7 +356,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "does not find the dependency" do bundle :install - expect(out).to include("Could not find gem 'rack', which is required by gem 'depends_on_rack', in any of the relevant sources") + expect(err).to include("Could not find gem 'rack', which is required by gem 'depends_on_rack', in any of the relevant sources") end end @@ -367,7 +375,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 @@ -388,7 +396,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "does not install the gem" do bundle :install - expect(out).to include("Could not find gem 'not_in_repo1'") + expect(err).to include("Could not find gem 'not_in_repo1'") end end @@ -437,7 +445,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "does not unlock the non-path gem after install" do bundle! :install - bundle! %(exec ruby -e 'puts "OK"'), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } + bundle! %(exec ruby -e 'puts "OK"') expect(out).to include("OK") end @@ -456,7 +464,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 @@ -544,7 +552,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "does not re-resolve" do - bundle :install, :verbose => true + bundle! :install, :verbose => true expect(out).to include("using resolution from the lockfile") expect(out).not_to include("re-resolving dependencies") end @@ -616,4 +624,63 @@ RSpec.describe "bundle install with gems on multiple sources" do end end end + + describe "source changed to one containing a higher version of a dependency" do + before do + install_gemfile! <<-G + source "file://#{gem_repo1}" + + gem "rack" + G + + build_repo2 do + build_gem "bar" + end + + build_lib("gemspec_test", :path => tmp.join("gemspec_test")) do |s| + s.add_dependency "bar", "=1.0.0" + end + + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "rack" + gemspec :path => "#{tmp.join("gemspec_test")}" + G + end + + it "keeps the old version", :bundler => "2" do + expect(the_bundle).to include_gems("rack 1.0.0") + end + + it "installs the higher version in the new repo", :bundler => "3" do + expect(the_bundle).to include_gems("rack 1.2") + end + end + + context "when a gem is available from multiple ambiguous sources", :bundler => "3" do + it "raises, suggesting a source block" do + build_repo4 do + build_gem "depends_on_rack" do |s| + s.add_dependency "rack" + end + build_gem "rack" + end + + install_gemfile <<-G + source "file://localhost#{gem_repo4}" + source "file://localhost#{gem_repo1}" do + gem "thin" + end + gem "depends_on_rack" + G + expect(last_command).to be_failure + 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 + You must add this gem to the source block for the source you wish it to be installed from. + EOS + expect(the_bundle).not_to be_locked + end + end end |