diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-01 23:29:38 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-01 23:29:38 +0000 |
commit | be7b5929126cb3e696ef222339237faba9b8fe5a (patch) | |
tree | 51eae376f93c09bc82dde5a657a91df2c89062e4 /spec/bundler/install | |
parent | ae49dbd392083f69026f2a0fff4a1d5f42d172a7 (diff) | |
download | ruby-be7b5929126cb3e696ef222339237faba9b8fe5a.tar.gz |
Update bundled bundler to 1.16.0.
* lib/bundler, spec/bundler: Merge bundler-1.16.0.
* common.mk: rspec examples of bundler-1.16.0 needs require option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/bundler/install')
38 files changed, 1486 insertions, 437 deletions
diff --git a/spec/bundler/install/allow_offline_install_spec.rb b/spec/bundler/install/allow_offline_install_spec.rb index 1bca055c9f..d4bb595771 100644 --- a/spec/bundler/install/allow_offline_install_spec.rb +++ b/spec/bundler/install/allow_offline_install_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with :allow_offline_install" do before do @@ -27,8 +26,9 @@ RSpec.describe "bundle install with :allow_offline_install" do context "with cached data locally" do it "will install from the compact index" do - system_gems ["rack-1.0.0"] + system_gems ["rack-1.0.0"], :path => :bundle_path + bundle! "config clean false" install_gemfile! <<-G, :artifice => "compact_index" source "http://testgemserver.local" gem "rack-obama" @@ -42,8 +42,8 @@ RSpec.describe "bundle install with :allow_offline_install" do gem "rack-obama" G - bundle! :update, :artifice => "fail" - expect(out).to include("Using the cached data for the new index because of a network error") + bundle! :update, :artifice => "fail", :all => true + expect(last_command.stdboth).to include "Using the cached data for the new index because of a network error" expect(the_bundle).to include_gems("rack-obama 1.0", "rack 1.0.0") end @@ -76,7 +76,7 @@ RSpec.describe "bundle install with :allow_offline_install" do gem "a", :git => #{git.path.to_s.dump} G - break_git_remote_ops! { bundle! :update } + break_git_remote_ops! { bundle! :update, :all => true } expect(out).to include("Using cached git data because of network errors") expect(the_bundle).to be_locked diff --git a/spec/bundler/install/binstubs_spec.rb b/spec/bundler/install/binstubs_spec.rb index a1a9ab167d..23eb691ab8 100644 --- a/spec/bundler/install/binstubs_spec.rb +++ b/spec/bundler/install/binstubs_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require "spec_helper" -RSpec.describe "bundle install" do +RSpec.describe "bundle install", :bundler => "< 2" do describe "when system_bindir is set" do # On OS X, Gem.bindir defaults to /usr/bin, so system_bindir is useful if # you want to avoid sudo installs for system gems with OS X's default ruby @@ -21,7 +20,7 @@ RSpec.describe "bundle install" do end end - describe "when multiple gems contain the same exe" do + describe "when multiple gems contain the same exe", :bundler => "< 2" do before do build_repo2 do build_gem "fake", "14" do |s| @@ -36,12 +35,6 @@ RSpec.describe "bundle install" do G end - it "prints a deprecation notice" do - bundle "config major_deprecations true" - gembin("rackup") - expect(out).to include("Bundler is using a binstub that was created for a different gem.") - end - it "loads the correct spec's executable" do gembin("rackup") expect(out).to eq("1.2") diff --git a/spec/bundler/install/bundler_spec.rb b/spec/bundler/install/bundler_spec.rb index c1ce57e60e..08b7e2b673 100644 --- a/spec/bundler/install/bundler_spec.rb +++ b/spec/bundler/install/bundler_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do describe "with bundler dependencies" do @@ -38,8 +37,6 @@ RSpec.describe "bundle install" do G nice_error = <<-E.strip.gsub(/^ {8}/, "") - Fetching source index from file:#{gem_repo2}/ - Resolving dependencies... Bundler could not find compatible versions for gem "bundler": In Gemfile: bundler (= 0.9.2) @@ -49,9 +46,9 @@ RSpec.describe "bundle install" do This Gemfile requires a different version of Bundler. Perhaps you need to update Bundler by running `gem install bundler`? - Could not find gem 'bundler (= 0.9.2)' in any of the sources + Could not find gem 'bundler (= 0.9.2)' in any E - expect(out).to eq(nice_error) + expect(last_command.bundler_err).to include(nice_error) end it "works for gems with multiple versions in its dependencies" do @@ -99,8 +96,6 @@ RSpec.describe "bundle install" do G nice_error = <<-E.strip.gsub(/^ {8}/, "") - Fetching source index from file:#{gem_repo2}/ - Resolving dependencies... Bundler could not find compatible versions for gem "activesupport": In Gemfile: activemerchant was resolved to 1.0, which depends on @@ -109,7 +104,7 @@ RSpec.describe "bundle install" do rails_fail was resolved to 1.0, which depends on activesupport (= 1.2.3) E - expect(out).to include(nice_error) + expect(last_command.bundler_err).to include(nice_error) end it "causes a conflict if a child dependency conflicts with the Gemfile" do @@ -120,8 +115,6 @@ RSpec.describe "bundle install" do G nice_error = <<-E.strip.gsub(/^ {8}/, "") - Fetching source index from file:#{gem_repo2}/ - Resolving dependencies... Bundler could not find compatible versions for gem "activesupport": In Gemfile: activesupport (= 2.3.5) @@ -129,19 +122,55 @@ RSpec.describe "bundle install" do rails_fail was resolved to 1.0, which depends on activesupport (= 1.2.3) E - expect(out).to include(nice_error) + expect(last_command.bundler_err).to include(nice_error) end - it "can install dependencies with newer bundler version" do - install_gemfile <<-G + it "can install dependencies with newer bundler version with system gems", :ruby => "> 2" do + bundle! "config path.system true" + install_gemfile! <<-G + source "file://#{gem_repo2}" + gem "rails", "3.0" + G + + simulate_bundler_version "99999999.99.1" + + bundle! "check", :env => { "BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD" => "1" } + expect(out).to include("The Gemfile's dependencies are satisfied") + end + + it "can install dependencies with newer bundler version with a local path", :ruby => "> 2" do + bundle! "config path .bundle" + install_gemfile! <<-G source "file://#{gem_repo2}" gem "rails", "3.0" G - simulate_bundler_version "10.0.0" + simulate_bundler_version "99999999.99.1" - bundle "check" + bundle! "check", :env => { "BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD" => "1" } expect(out).to include("The Gemfile's dependencies are satisfied") end + + context "with allow_bundler_dependency_conflicts set" do + before { bundle! "config allow_bundler_dependency_conflicts true" } + + it "are forced to the current bundler version with warnings when no compatible version is found" do + build_repo4 do + build_gem "requires_nonexistant_bundler" do |s| + s.add_runtime_dependency "bundler", "99.99.99.99" + end + end + + install_gemfile! <<-G + source "file://#{gem_repo4}" + gem "requires_nonexistant_bundler" + G + + expect(out).to include "requires_nonexistant_bundler (1.0) has dependency bundler (= 99.99.99.99), " \ + "which is unsatisfied by the current bundler version #{Bundler::VERSION}, so the dependency is being ignored" + + expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}", "requires_nonexistant_bundler 1.0" + end + end end end diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index bcbd57bc4f..3b9d68982a 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "install with --deployment or --frozen" do before do @@ -9,44 +8,48 @@ RSpec.describe "install with --deployment or --frozen" do G end - it "fails without a lockfile and says that --deployment requires a lock" do - bundle "install --deployment" - expect(out).to include("The --deployment flag requires a Gemfile.lock") - end + context "with CLI flags", :bundler => "< 2" do + it "fails without a lockfile and says that --deployment requires a lock" do + bundle "install --deployment" + expect(out).to include("The --deployment flag requires a Gemfile.lock") + end - it "fails without a lockfile and says that --frozen requires a lock" do - bundle "install --frozen" - expect(out).to include("The --frozen flag requires a Gemfile.lock") - end + it "fails without a lockfile and says that --frozen requires a lock" do + bundle "install --frozen" + expect(out).to include("The --frozen flag requires a Gemfile.lock") + end - it "disallows --deployment --system" do - bundle "install --deployment --system" - expect(out).to include("You have specified both --deployment") - expect(out).to include("Please choose only one option") - expect(exitstatus).to eq(15) if exitstatus - end + it "disallows --deployment --system" do + bundle "install --deployment --system" + expect(out).to include("You have specified both --deployment") + expect(out).to include("Please choose only one option") + expect(exitstatus).to eq(15) if exitstatus + end - it "disallows --deployment --path --system" do - bundle "install --deployment --path . --system" - expect(out).to include("You have specified both --path") - expect(out).to include("as well as --system") - expect(out).to include("Please choose only one option") - expect(exitstatus).to eq(15) if exitstatus - end + it "disallows --deployment --path --system" do + bundle "install --deployment --path . --system" + expect(out).to include("You have specified both --path") + expect(out).to include("as well as --system") + expect(out).to include("Please choose only one option") + expect(exitstatus).to eq(15) if exitstatus + end - it "works after you try to deploy without a lock" do - bundle "install --deployment" - bundle :install - expect(exitstatus).to eq(0) if exitstatus - expect(the_bundle).to include_gems "rack 1.0" + it "works after you try to deploy without a lock" do + bundle "install --deployment" + bundle! :install + expect(the_bundle).to include_gems "rack 1.0" + end end it "still works if you are not in the app directory and specify --gemfile" do bundle "install" - Dir.chdir tmp - simulate_new_machine - bundle "install --gemfile #{tmp}/bundled_app/Gemfile --deployment" - Dir.chdir bundled_app + Dir.chdir tmp do + simulate_new_machine + bundle! :install, + forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", + :deployment => true, + :path => "vendor/bundle") + end expect(the_bundle).to include_gems "rack 1.0" end @@ -58,15 +61,13 @@ RSpec.describe "install with --deployment or --frozen" do end G bundle :install - bundle "install --deployment --without test" - expect(exitstatus).to eq(0) if exitstatus + bundle! :install, forgotten_command_line_options(:deployment => true, :without => "test") end - it "works when you bundle exec bundle" do + it "works when you bundle exec bundle", :ruby_repo do bundle :install bundle "install --deployment" - bundle "exec bundle check" - expect(exitstatus).to eq(0) if exitstatus + bundle! "exec bundle check" end it "works when using path gems from the same path and the version is specified" do @@ -78,7 +79,7 @@ RSpec.describe "install with --deployment or --frozen" do G bundle! :install - bundle! "install --deployment" + bundle! :install, forgotten_command_line_options(:deployment => true) end it "works when there are credentials in the source URL" do @@ -88,21 +89,18 @@ RSpec.describe "install with --deployment or --frozen" do gem "rack-obama", ">= 1.0" G - bundle "install --deployment", :artifice => "endpoint_strict_basic_authentication" - - expect(exitstatus).to eq(0) if exitstatus + bundle! :install, forgotten_command_line_options(:deployment => true).merge(:artifice => "endpoint_strict_basic_authentication") end it "works with sources given by a block" do - install_gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" do gem "rack" end G - bundle "install --deployment" + bundle! :install, forgotten_command_line_options(:deployment => true) - expect(exitstatus).to eq(0) if exitstatus expect(the_bundle).to include_gems "rack 1.0" end @@ -111,14 +109,16 @@ RSpec.describe "install with --deployment or --frozen" do bundle "install" end - it "works with the --deployment flag if you didn't change anything" do - bundle "install --deployment" - expect(exitstatus).to eq(0) if exitstatus + it "works with the --deployment flag if you didn't change anything", :bundler => "< 2" do + bundle! "install --deployment" end - it "works with the --frozen flag if you didn't change anything" do - bundle "install --frozen" - expect(exitstatus).to eq(0) if exitstatus + it "works with the --frozen flag if you didn't change anything", :bundler => "< 2" do + bundle! "install --frozen" + end + + it "works with BUNDLE_FROZEN if you didn't change anything" do + bundle! :install, :env => { "BUNDLE_FROZEN" => "true" } end it "explodes with the --deployment flag if you make a change and don't check in the lockfile" do @@ -128,7 +128,7 @@ RSpec.describe "install with --deployment or --frozen" do gem "rack-obama" G - bundle "install --deployment" + bundle :install, forgotten_command_line_options(:deployment => true) expect(out).to include("deployment mode") expect(out).to include("You have added to the Gemfile") expect(out).to include("* rack-obama") @@ -136,7 +136,36 @@ RSpec.describe "install with --deployment or --frozen" do expect(out).not_to include("You have changed in the Gemfile") end - it "can have --frozen set via an environment variable" do + it "works if a path gem is missing but is in a without group" do + build_lib "path_gem" + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rake" + gem "path_gem", :path => "#{lib_path("path_gem-1.0")}", :group => :development + G + expect(the_bundle).to include_gems "path_gem 1.0" + FileUtils.rm_r lib_path("path_gem-1.0") + + bundle! :install, forgotten_command_line_options(:path => ".bundle", :without => "development", :deployment => true).merge(:env => { :DEBUG => "1" }) + run! "puts :WIN" + expect(out).to eq("WIN") + end + + it "explodes if a path gem is missing" do + build_lib "path_gem" + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rake" + gem "path_gem", :path => "#{lib_path("path_gem-1.0")}", :group => :development + G + expect(the_bundle).to include_gems "path_gem 1.0" + FileUtils.rm_r lib_path("path_gem-1.0") + + bundle :install, forgotten_command_line_options(:path => ".bundle", :deployment => true) + expect(out).to include("The path `#{lib_path("path_gem-1.0")}` does not exist.") + end + + it "can have --frozen set via an environment variable", :bundler => "< 2" do gemfile <<-G source "file://#{gem_repo1}" gem "rack" @@ -152,6 +181,22 @@ RSpec.describe "install with --deployment or --frozen" do expect(out).not_to include("You have changed in the Gemfile") end + it "can have --deployment set via an environment variable" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rack-obama" + G + + ENV["BUNDLE_DEPLOYMENT"] = "true" + bundle "install" + expect(out).to include("deployment mode") + expect(out).to include("You have added to the Gemfile") + expect(out).to include("* rack-obama") + expect(out).not_to include("You have deleted from the Gemfile") + expect(out).not_to include("You have changed in the Gemfile") + end + it "can have --frozen set to false via an environment variable" do gemfile <<-G source "file://#{gem_repo1}" @@ -160,20 +205,21 @@ RSpec.describe "install with --deployment or --frozen" do G ENV["BUNDLE_FROZEN"] = "false" + ENV["BUNDLE_DEPLOYMENT"] = "false" bundle "install" expect(out).not_to include("deployment mode") expect(out).not_to include("You have added to the Gemfile") expect(out).not_to include("* rack-obama") end - it "explodes with the --frozen flag if you make a change and don't check in the lockfile" do + it "explodes with the --frozen flag if you make a change and don't check in the lockfile", :bundler => "< 2" do gemfile <<-G source "file://#{gem_repo1}" gem "rack" gem "rack-obama", "1.1" G - bundle "install --frozen" + bundle :install, forgotten_command_line_options(:frozen => true) expect(out).to include("deployment mode") expect(out).to include("You have added to the Gemfile") expect(out).to include("* rack-obama (= 1.1)") @@ -187,7 +233,7 @@ RSpec.describe "install with --deployment or --frozen" do gem "activesupport" G - bundle "install --deployment" + bundle :install, forgotten_command_line_options(:deployment => true) expect(out).to include("deployment mode") expect(out).to include("You have added to the Gemfile:\n* activesupport\n\n") expect(out).to include("You have deleted from the Gemfile:\n* rack") @@ -200,7 +246,7 @@ RSpec.describe "install with --deployment or --frozen" do gem "rack", :git => "git://hubz.com" G - bundle "install --deployment" + bundle :install, forgotten_command_line_options(:deployment => true) expect(out).to include("deployment mode") expect(out).to include("You have added to the Gemfile:\n* source: git://hubz.com (at master)") expect(out).not_to include("You have changed in the Gemfile") @@ -219,7 +265,7 @@ RSpec.describe "install with --deployment or --frozen" do gem "rack" G - bundle "install --deployment" + bundle :install, forgotten_command_line_options(:deployment => true) expect(out).to include("deployment mode") expect(out).to include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")} (at master@#{revision_for(lib_path("rack-1.0"))[0..6]}") expect(out).not_to include("You have added to the Gemfile") @@ -242,15 +288,93 @@ RSpec.describe "install with --deployment or --frozen" do gem "foo", :git => "#{lib_path("rack")}" G - bundle "install --deployment" + bundle :install, forgotten_command_line_options(:deployment => true) expect(out).to include("deployment mode") expect(out).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `#{lib_path("rack")} (at master@#{revision_for(lib_path("rack"))[0..6]})`") expect(out).not_to include("You have added to the Gemfile") expect(out).not_to include("You have deleted from the Gemfile") end + context "when replacing a host with the same host with credentials" do + let(:success_message) do + if Bundler::VERSION.split(".", 2).first == "1" + "Could not reach host localgemserver.test" + else + "Bundle complete!" + end + end + + before do + install_gemfile <<-G + source "http://user_name:password@localgemserver.test/" + gem "rack" + G + + lockfile <<-G + GEM + remote: http://localgemserver.test/ + specs: + rack (1.0.0) + + PLATFORMS + #{local} + + DEPENDENCIES + rack + G + end + + it "prevents the replace by default" do + bundle :install, forgotten_command_line_options(:deployment => true) + + expect(out).to match(/The list of sources changed/) + end + + context "when allow_deployment_source_credential_changes is true" do + before { bundle! "config allow_deployment_source_credential_changes true" } + + it "allows the replace" do + bundle :install, forgotten_command_line_options(:deployment => true) + + expect(out).to match(/#{success_message}/) + end + end + + context "when allow_deployment_source_credential_changes is false" do + before { bundle! "config allow_deployment_source_credential_changes false" } + + it "prevents the replace" do + bundle :install, forgotten_command_line_options(:deployment => true) + + expect(out).to match(/The list of sources changed/) + end + end + + context "when BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES env var is true" do + before { ENV["BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES"] = "true" } + + it "allows the replace" do + bundle :install, forgotten_command_line_options(:deployment => true) + + expect(out).to match(/#{success_message}/) + end + end + + context "when BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES env var is false" do + before { ENV["BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES"] = "false" } + + it "prevents the replace" do + bundle :install, forgotten_command_line_options(:deployment => true) + + expect(out).to match(/The list of sources changed/) + end + end + end + it "remembers that the bundle is frozen at runtime" do - bundle "install --deployment" + bundle! :lock + + bundle! "config deployment true" gemfile <<-G source "file://#{gem_repo1}" @@ -281,19 +405,17 @@ You have deleted from the Gemfile: bundle! :install expect(the_bundle).to include_gems "foo 1.0" - bundle! "package --all" + bundle! :package, forgotten_command_line_options([:all, :cache_all] => true) expect(bundled_app("vendor/cache/foo")).to be_directory bundle! "install --local" - expect(out).to include("Using foo 1.0 from source at") - expect(out).to include("vendor/cache/foo") + expect(out).to include("Updating files in vendor/cache") simulate_new_machine - bundle! "install --deployment --verbose" + bundle! "install --verbose", forgotten_command_line_options(:deployment => true) expect(out).not_to include("You are trying to install in deployment mode after changing your Gemfile") expect(out).not_to include("You have added to the Gemfile") expect(out).not_to include("You have deleted from the Gemfile") - expect(out).to include("Using foo 1.0 from source at") expect(out).to include("vendor/cache/foo") expect(the_bundle).to include_gems "foo 1.0" end diff --git a/spec/bundler/install/failure_spec.rb b/spec/bundler/install/failure_spec.rb index 738b2cf1bd..896138c659 100644 --- a/spec/bundler/install/failure_spec.rb +++ b/spec/bundler/install/failure_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do context "installing a gem fails" do @@ -19,7 +18,7 @@ RSpec.describe "bundle install" do source "file:#{gem_repo2}" gem "rails" G - expect(out).to end_with(<<-M.strip) + expect(last_command.bundler_err).to end_with(<<-M.strip) An error occurred while installing activesupport (2.3.2), and Bundler cannot continue. Make sure that `gem install activesupport -v '2.3.2'` succeeds before bundling. diff --git a/spec/bundler/install/force_spec.rb b/spec/bundler/install/force_spec.rb index dc4956a7ae..52fa4f0d61 100644 --- a/spec/bundler/install/force_spec.rb +++ b/spec/bundler/install/force_spec.rb @@ -1,66 +1,61 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do - describe "with --force" do - before :each do - gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G - end + %w[force redownload].each do |flag| + describe_opts = {} + describe_opts[:bundler] = "< 2" if flag == "force" + describe "with --#{flag}", describe_opts do + before :each do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + end - it "re-installs installed gems" do - rack_lib = default_bundle_path("gems/rack-1.0.0/lib/rack.rb") + it "re-installs installed gems" do + rack_lib = default_bundle_path("gems/rack-1.0.0/lib/rack.rb") - bundle "install" - rack_lib.open("w") {|f| f.write("blah blah blah") } - bundle "install --force" + bundle! :install + rack_lib.open("w") {|f| f.write("blah blah blah") } + bundle! :install, flag => true - expect(exitstatus).to eq(0) if exitstatus - expect(out).to include "Using bundler" - expect(out).to include "Installing rack 1.0.0" - expect(rack_lib.open(&:read)).to eq("RACK = '1.0.0'\n") - expect(the_bundle).to include_gems "rack 1.0.0" - end + expect(out).to include "Installing rack 1.0.0" + expect(rack_lib.open(&:read)).to eq("RACK = '1.0.0'\n") + expect(the_bundle).to include_gems "rack 1.0.0" + end - it "works on first bundle install" do - bundle "install --force" + it "works on first bundle install" do + bundle! :install, flag => true - expect(exitstatus).to eq(0) if exitstatus - expect(out).to include "Using bundler" - expect(out).to include "Installing rack 1.0.0" - expect(the_bundle).to include_gems "rack 1.0.0" - end + expect(out).to include "Installing rack 1.0.0" + expect(the_bundle).to include_gems "rack 1.0.0" + end - context "with a git gem" do - let!(:ref) { build_git("foo", "1.0").ref_for("HEAD", 11) } + context "with a git gem" do + let!(:ref) { build_git("foo", "1.0").ref_for("HEAD", 11) } - before do - gemfile <<-G - gem "foo", :git => "#{lib_path("foo-1.0")}" - G - end + before do + gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}" + G + end - it "re-installs installed gems" do - foo_lib = default_bundle_path("bundler/gems/foo-1.0-#{ref}/lib/foo.rb") + it "re-installs installed gems" do + foo_lib = default_bundle_path("bundler/gems/foo-1.0-#{ref}/lib/foo.rb") - bundle! "install" - foo_lib.open("w") {|f| f.write("blah blah blah") } - bundle! "install --force" + bundle! :install + foo_lib.open("w") {|f| f.write("blah blah blah") } + bundle! :install, flag => true - expect(out).to include "Using bundler" - expect(out).to include "Using foo 1.0 from #{lib_path("foo-1.0")} (at master@#{ref[0, 7]})" - expect(foo_lib.open(&:read)).to eq("FOO = '1.0'\n") - expect(the_bundle).to include_gems "foo 1.0" - end + expect(foo_lib.open(&:read)).to eq("FOO = '1.0'\n") + expect(the_bundle).to include_gems "foo 1.0" + end - it "works on first bundle install" do - bundle! "install --force" + it "works on first bundle install" do + bundle! :install, flag => true - expect(out).to include "Using bundler" - expect(out).to include "Using foo 1.0 from #{lib_path("foo-1.0")} (at master@#{ref[0, 7]})" - expect(the_bundle).to include_gems "foo 1.0" + expect(the_bundle).to include_gems "foo 1.0" + end end end end diff --git a/spec/bundler/install/gemfile/eval_gemfile_spec.rb b/spec/bundler/install/gemfile/eval_gemfile_spec.rb index f02223d34d..035d3692aa 100644 --- a/spec/bundler/install/gemfile/eval_gemfile_spec.rb +++ b/spec/bundler/install/gemfile/eval_gemfile_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with gemfile that uses eval_gemfile" do before do @@ -21,8 +20,9 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do eval_gemfile 'Gemfile-other' G expect(out).to include("Resolving dependencies") - expect(out).to include("Using gunks 0.0.1 from source at `gems/gunks`") expect(out).to include("Bundle complete") + + expect(the_bundle).to include_gem "gunks 0.0.1", :source => "path@#{bundled_app("gems", "gunks")}" end end @@ -47,7 +47,7 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do # parsed lockfile and the evaluated gemfile. it "bundles with --deployment" do bundle! :install - bundle! "install --deployment" + bundle! :install, forgotten_command_line_options(:deployment => true) end end @@ -60,8 +60,23 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do gemspec :path => 'gems/gunks' G expect(out).to include("Resolving dependencies") - expect(out).to include("Using gunks 0.0.1 from source at `gems/gunks`") expect(out).to include("Bundle complete") + + expect(the_bundle).to include_gem "gunks 0.0.1", :source => "path@#{bundled_app("gems", "gunks")}" + end + end + + context "eval-ed Gemfile references other gemfiles" do + it "works with relative paths" do + create_file "other/Gemfile-other", "gem 'rack'" + create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'" + create_file "Gemfile-alt", <<-G + source "file:#{gem_repo1}" + eval_gemfile "other/Gemfile" + G + install_gemfile! "eval_gemfile File.expand_path('Gemfile-alt')" + + expect(the_bundle).to include_gem "rack 1.0.0" end end end diff --git a/spec/bundler/install/gemfile/gemspec_spec.rb b/spec/bundler/install/gemfile/gemspec_spec.rb index 1ea613c9d2..1dc016ed23 100644 --- a/spec/bundler/install/gemfile/gemspec_spec.rb +++ b/spec/bundler/install/gemfile/gemspec_spec.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install from an existing gemspec" do before(:each) do - build_gem "bar", :to_system => true - build_gem "bar-dev", :to_system => true + build_repo2 do + build_gem "bar" + build_gem "bar-dev" + end end it "should install runtime and development dependencies" do @@ -40,8 +41,10 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should handle a list of requirements" do - build_gem "baz", "1.0", :to_system => true - build_gem "baz", "1.1", :to_system => true + update_repo2 do + build_gem "baz", "1.0" + build_gem "baz", "1.1" + end build_lib("foo", :path => tmp.join("foo")) do |s| s.write("Gemfile", "source :rubygems\ngemspec") @@ -58,11 +61,11 @@ RSpec.describe "bundle install from an existing gemspec" do it "should raise if there are no gemspecs available" do build_lib("foo", :path => tmp.join("foo"), :gemspec => false) - error = install_gemfile(<<-G) + install_gemfile(<<-G) source "file://#{gem_repo2}" gemspec :path => '#{tmp.join("foo")}' G - expect(error).to match(/There are no gemspecs at #{tmp.join('foo')}/) + expect(last_command.bundler_err).to match(/There are no gemspecs at #{tmp.join('foo')}/) end it "should raise if there are too many gemspecs available" do @@ -70,11 +73,11 @@ RSpec.describe "bundle install from an existing gemspec" do s.write("foo2.gemspec", build_spec("foo", "4.0").first.to_ruby) end - error = install_gemfile(<<-G) + install_gemfile(<<-G) source "file://#{gem_repo2}" gemspec :path => '#{tmp.join("foo")}' G - expect(error).to match(/There are multiple gemspecs at #{tmp.join('foo')}/) + expect(last_command.bundler_err).to match(/There are multiple gemspecs at #{tmp.join('foo')}/) end it "should pick a specific gemspec" do @@ -142,7 +145,9 @@ RSpec.describe "bundle install from an existing gemspec" do G bundle! "install", :verbose => true - expect(out).to include("Found no changes, using resolution from the lockfile") + + message = "Found no changes, using resolution from the lockfile" + expect(out.scan(message).size).to eq(1) end it "should match a lockfile without needing to re-resolve with development dependencies" do @@ -159,7 +164,9 @@ RSpec.describe "bundle install from an existing gemspec" do G bundle! "install", :verbose => true - expect(out).to include("Found no changes, using resolution from the lockfile") + + message = "Found no changes, using resolution from the lockfile" + expect(out.scan(message).size).to eq(1) end it "should match a lockfile on non-ruby platforms with a transitive platform dependency" do @@ -170,7 +177,7 @@ RSpec.describe "bundle install from an existing gemspec" do s.add_dependency "platform_specific" end - install_gem "platform_specific-1.0-java" + system_gems "platform_specific-1.0-java", :path => :bundle_path, :keep_path => true install_gemfile! <<-G gemspec :path => '#{tmp.join("foo")}' @@ -189,15 +196,16 @@ RSpec.describe "bundle install from an existing gemspec" do install_gemfile <<-G gemspec :path => '#{tmp.join("foo")}' G - expect(@err).not_to match(/ahh/) + expect(last_command.stdboth).not_to include("ahh") end it "allows the gemspec to activate other gems" do + ENV["BUNDLE_PATH__SYSTEM"] = "true" # see https://github.com/bundler/bundler/issues/5409 # # issue was caused by rubygems having an unresolved gem during a require, # so emulate that - system_gems %w(rack-1.0.0 rack-0.9.1 rack-obama-1.0) + system_gems %w[rack-1.0.0 rack-0.9.1 rack-obama-1.0] build_lib("foo", :path => bundled_app) gemspec = bundled_app("foo.gemspec").read @@ -217,10 +225,10 @@ RSpec.describe "bundle install from an existing gemspec" do s.version = "1.0.0" s.add_dependency "bar", "= 1.0.0" end - build_gem "deps", :to_system => true do |s| + build_gem "deps", :to_bundle => true do |s| s.add_dependency "foo", "= 0.0.1" end - build_gem "foo", "0.0.1", :to_system => true + build_gem "foo", "0.0.1", :to_bundle => true install_gemfile <<-G source "file://#{gem_repo2}" @@ -236,7 +244,7 @@ RSpec.describe "bundle install from an existing gemspec" do s.version = "1.0.0" s.add_dependency "bar", "= 1.0.0" end - build_repo2 do + update_repo2 do build_gem "deps" do |s| s.add_dependency "foo", "= 0.0.1" end @@ -273,7 +281,7 @@ RSpec.describe "bundle install from an existing gemspec" do s.add_dependency "activesupport", ">= 1.0.1" end - bundle "install --deployment" + bundle :install, forgotten_command_line_options(:deployment => true) expect(out).to include("changed") end @@ -415,7 +423,7 @@ RSpec.describe "bundle install from an existing gemspec" do end end - %w(ruby jruby).each do |platform| + %w[ruby jruby].each do |platform| simulate_platform(platform) do install_gemfile <<-G source "file://#{gem_repo2}" @@ -425,7 +433,7 @@ RSpec.describe "bundle install from an existing gemspec" do end end - context "on ruby" do + context "on ruby", :bundler => "< 2" do before do simulate_platform("ruby") bundle :install @@ -525,6 +533,107 @@ RSpec.describe "bundle install from an existing gemspec" do end end end + + context "on ruby", :bundler => "2" do + before do + simulate_platform("ruby") + bundle :install + end + + context "as a runtime dependency" do + it "keeps java dependencies in the lockfile" do + expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 RUBY" + expect(lockfile).to eq strip_whitespace(<<-L) + GEM + remote: file:#{gem_repo2}/ + specs: + platform_specific (1.0) + platform_specific (1.0-java) + + PATH + remote: . + specs: + foo (1.0) + platform_specific + + PLATFORMS + java + ruby + + DEPENDENCIES + foo! + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + + context "as a development dependency" do + let(:platform_specific_type) { :development } + + it "keeps java dependencies in the lockfile" do + expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 RUBY" + expect(lockfile).to eq strip_whitespace(<<-L) + GEM + remote: file:#{gem_repo2}/ + specs: + platform_specific (1.0) + platform_specific (1.0-java) + + PATH + remote: . + specs: + foo (1.0) + + PLATFORMS + java + ruby + + DEPENDENCIES + foo! + platform_specific + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + + context "with an indirect platform-specific development dependency" do + let(:platform_specific_type) { :development } + let(:dependency) { "indirect_platform_specific" } + + it "keeps java dependencies in the lockfile" do + expect(the_bundle).to include_gems "foo 1.0", "indirect_platform_specific 1.0", "platform_specific 1.0 RUBY" + expect(lockfile).to eq strip_whitespace(<<-L) + GEM + remote: file:#{gem_repo2}/ + specs: + indirect_platform_specific (1.0) + platform_specific + platform_specific (1.0) + platform_specific (1.0-java) + + PATH + remote: . + specs: + foo (1.0) + + PLATFORMS + java + ruby + + DEPENDENCIES + foo! + indirect_platform_specific + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + end end end @@ -551,7 +660,7 @@ RSpec.describe "bundle install from an existing gemspec" do it "installs the ruby platform gemspec and skips dev deps with --without development" do simulate_platform "ruby" - install_gemfile! <<-G, :without => "development" + install_gemfile! <<-G, forgotten_command_line_options(:without => "development") source "file://#{gem_repo1}" gemspec :path => '#{tmp.join("foo")}', :name => 'foo' G diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 5868c76570..57d83a5295 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with git sources" do describe "when floating on master" do @@ -27,8 +26,15 @@ RSpec.describe "bundle install with git sources" do expect(out).to eq("WIN") end - it "caches the git repo" do - expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"].size).to eq(1) + it "caches the git repo", :bundler => "< 2" do + expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"]).to have_attributes :size => 1 + end + + it "caches the git repo globally" do + simulate_new_machine + bundle! "config global_gem_cache true" + bundle! :install + expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes :size => 1 end it "caches the evaluated gemspec" do @@ -81,7 +87,7 @@ RSpec.describe "bundle install with git sources" do gem "foo", "1.1", :git => "#{lib_path("foo-1.0")}" G - expect(out).to include("Source contains 'foo' at: 1.0 ruby") + expect(out).to include("The source contains 'foo' at: 1.0") end it "complains with version and platform if pinned specs don't exist in the git repo" do @@ -97,7 +103,7 @@ RSpec.describe "bundle install with git sources" do end G - expect(out).to include("Source contains 'only_java' at: 1.0 java") + expect(out).to include("The source contains 'only_java' at: 1.0 java") end it "complains with multiple versions and platforms if pinned specs don't exist in the git repo" do @@ -118,7 +124,7 @@ RSpec.describe "bundle install with git sources" do end G - expect(out).to include("Source contains 'only_java' at: 1.0 java, 1.1 java") + expect(out).to include("The source contains 'only_java' at: 1.0 java, 1.1 java") end it "still works after moving the application directory" do @@ -207,6 +213,95 @@ RSpec.describe "bundle install with git sources" do expect(out).to eq("WIN") end + + it "works when the revision is a non-head ref" do + # want to ensure we don't fallback to master + update_git "foo", :path => lib_path("foo-1.0") do |s| + s.write("lib/foo.rb", "raise 'FAIL'") + end + + Dir.chdir(lib_path("foo-1.0")) do + `git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1` + end + + # want to ensure we don't fallback to HEAD + update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| + s.write("lib/foo.rb", "raise 'FAIL'") + end + + install_gemfile! <<-G + git "#{lib_path("foo-1.0")}", :ref => "refs/bundler/1" do + gem "foo" + end + G + expect(err).to lack_errors + + run! <<-RUBY + require 'foo' + puts "WIN" if defined?(FOO) + RUBY + + expect(out).to eq("WIN") + end + + it "works when the revision is a non-head ref and it was previously downloaded" do + install_gemfile! <<-G + git "#{lib_path("foo-1.0")}" do + gem "foo" + end + G + + # want to ensure we don't fallback to master + update_git "foo", :path => lib_path("foo-1.0") do |s| + s.write("lib/foo.rb", "raise 'FAIL'") + end + + Dir.chdir(lib_path("foo-1.0")) do + `git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1` + end + + # want to ensure we don't fallback to HEAD + update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| + s.write("lib/foo.rb", "raise 'FAIL'") + end + + install_gemfile! <<-G + git "#{lib_path("foo-1.0")}", :ref => "refs/bundler/1" do + gem "foo" + end + G + expect(err).to lack_errors + + run! <<-RUBY + require 'foo' + puts "WIN" if defined?(FOO) + RUBY + + expect(out).to eq("WIN") + end + + it "does not download random non-head refs" do + Dir.chdir(lib_path("foo-1.0")) do + sys_exec!("git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1") + end + + bundle! "config global_gem_cache true" + + install_gemfile! <<-G + git "#{lib_path("foo-1.0")}" do + gem "foo" + end + G + + # ensure we also git fetch after cloning + bundle! :update, :all => bundle_update_requires_all? + + Dir.chdir(Dir[home(".bundle/cache/git/foo-*")].first) do + sys_exec("git ls-remote .") + end + + expect(out).not_to include("refs/bundler/1") + end end describe "when specifying a branch" do @@ -311,9 +406,8 @@ RSpec.describe "bundle install with git sources" do gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" G - bundle %(config local.rack #{lib_path("local-rack")}) - bundle :install - expect(out).to match(/at #{lib_path('local-rack')}/) + bundle! %(config local.rack #{lib_path("local-rack")}) + bundle! :install run "require 'rack'" expect(out).to eq("LOCAL") @@ -704,14 +798,14 @@ RSpec.describe "bundle install with git sources" do s.write "lib/forced.rb", "FORCED = '1.1'" end - bundle "update" + bundle "update", :all => bundle_update_requires_all? expect(the_bundle).to include_gems "forced 1.1" Dir.chdir(lib_path("forced-1.0")) do `git reset --hard HEAD^` end - bundle "update" + bundle "update", :all => bundle_update_requires_all? expect(the_bundle).to include_gems "forced 1.0" end @@ -808,6 +902,7 @@ RSpec.describe "bundle install with git sources" do it "prints a friendly error if a file blocks the git repo" do build_git "foo" + FileUtils.mkdir_p(default_bundle_path) FileUtils.touch(default_bundle_path("bundler")) install_gemfile <<-G @@ -937,8 +1032,7 @@ RSpec.describe "bundle install with git sources" do simulate_new_machine - bundle "install --deployment" - expect(exitstatus).to eq(0) if exitstatus + bundle! :install, forgotten_command_line_options(:deployment => true) end end @@ -1034,7 +1128,7 @@ RSpec.describe "bundle install with git sources" do run! <<-R puts $:.grep(/ext/) R - expect(out).to eq(Pathname.glob(system_gem_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) + expect(out).to eq(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) end it "does not use old extension after ref changes", :ruby_repo do @@ -1058,11 +1152,11 @@ RSpec.describe "bundle install with git sources" do end `git commit -m 'commit for iteration #{i}' ext/foo.c` end - git_sha = git_reader.ref_for("HEAD") + git_commit_sha = git_reader.ref_for("HEAD") install_gemfile <<-G source "file://#{gem_repo1}" - gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{git_sha}" + gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{git_commit_sha}" G run <<-R @@ -1090,7 +1184,7 @@ RSpec.describe "bundle install with git sources" do gem "foo", :git => "#{lib_path("foo-1.0")}" G - expect(out).to end_with(<<-M.strip) + expect(last_command.bundler_err).to end_with(<<-M.strip) An error occurred while installing foo (1.0), and Bundler cannot continue. In Gemfile: @@ -1174,9 +1268,10 @@ In Gemfile: G with_path_as("") do - bundle "update" + bundle "update", :all => bundle_update_requires_all? end - expect(out).to include("You need to install git to be able to use gems from git repositories. For help installing git, please refer to GitHub's tutorial at https://help.github.com/articles/set-up-git") + expect(last_command.bundler_err). + to include("You need to install git to be able to use gems from git repositories. For help installing git, please refer to GitHub's tutorial at https://help.github.com/articles/set-up-git") end it "installs a packaged git gem successfully" do @@ -1187,18 +1282,17 @@ In Gemfile: gem 'foo' end G - bundle "package --all" + bundle :package, forgotten_command_line_options([:all, :cache_all] => true) simulate_new_machine - bundle "install", :env => { "PATH" => "" } + bundle! "install", :env => { "PATH" => "" } expect(out).to_not include("You need to install git to be able to use gems from git repositories.") - expect(exitstatus).to be_zero if exitstatus end end - describe "when the git source is overriden with a local git repo" do + describe "when the git source is overridden with a local git repo" do before do - bundle "config --global local.foo #{lib_path("foo")}" + bundle! "config --global local.foo #{lib_path("foo")}" end describe "and git output is colorized" do @@ -1233,9 +1327,8 @@ In Gemfile: G bundle :install - expect(out).to_not include("password1") - expect(err).to_not include("password1") - expect(out).to include("Fetching https://user1@github.com/company/private-repo") + expect(last_command.stdboth).to_not include("password1") + expect(last_command.stdout).to include("Fetching https://user1@github.com/company/private-repo") end end @@ -1250,9 +1343,8 @@ In Gemfile: G bundle :install - expect(out).to_not include("oauth_token") - expect(err).to_not include("oauth_token") - expect(out).to include("Fetching https://x-oauth-basic@github.com/company/private-repo") + expect(last_command.stdboth).to_not include("oauth_token") + expect(last_command.stdout).to include("Fetching https://x-oauth-basic@github.com/company/private-repo") end end end diff --git a/spec/bundler/install/gemfile/groups_spec.rb b/spec/bundler/install/gemfile/groups_spec.rb index a3a5eeefdf..19c379e188 100644 --- a/spec/bundler/install/gemfile/groups_spec.rb +++ b/spec/bundler/install/gemfile/groups_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with groups" do describe "installing with no options" do @@ -87,7 +86,7 @@ RSpec.describe "bundle install with groups" do end it "installs gems in the default group" do - bundle :install, :without => "emo" + bundle! :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).to include_gems "rack 1.0.0", :groups => [:default] end @@ -97,20 +96,20 @@ RSpec.describe "bundle install with groups" do end it "does not install gems from the previously excluded group" do - bundle :install, :without => "emo" + bundle :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).not_to include_gems "activesupport 2.3.5" bundle :install expect(the_bundle).not_to include_gems "activesupport 2.3.5" end it "does not say it installed gems from the excluded group" do - bundle :install, :without => "emo" + bundle! :install, forgotten_command_line_options(:without => "emo") expect(out).not_to include("activesupport") end it "allows Bundler.setup for specific groups" do - bundle :install, :without => "emo" - run("require 'rack'; puts RACK", :default) + bundle :install, forgotten_command_line_options(:without => "emo") + run!("require 'rack'; puts RACK", :default) expect(out).to eq("1.0.0") end @@ -123,15 +122,15 @@ RSpec.describe "bundle install with groups" do end G - bundle :install, :without => "emo" + bundle :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).to include_gems "activesupport 2.3.2", :groups => [:default] end it "still works on a different machine and excludes gems" do - bundle :install, :without => "emo" + bundle :install, forgotten_command_line_options(:without => "emo") simulate_new_machine - bundle :install, :without => "emo" + bundle :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).to include_gems "rack 1.0.0", :groups => [:default] expect(the_bundle).not_to include_gems "activesupport 2.3.5", :groups => [:default] @@ -150,14 +149,14 @@ RSpec.describe "bundle install with groups" do end it "clears without when passed an empty list" do - bundle :install, :without => "emo" + bundle :install, forgotten_command_line_options(:without => "emo") - bundle 'install --without ""' + bundle :install, forgotten_command_line_options(:without => "") expect(the_bundle).to include_gems "activesupport 2.3.5" end it "doesn't clear without when nothing is passed" do - bundle :install, :without => "emo" + bundle :install, forgotten_command_line_options(:without => "emo") bundle :install expect(the_bundle).not_to include_gems "activesupport 2.3.5" @@ -169,12 +168,12 @@ RSpec.describe "bundle install with groups" do end it "does install gems from the optional group when requested" do - bundle :install, :with => "debugging" + bundle :install, forgotten_command_line_options(:with => "debugging") expect(the_bundle).to include_gems "thin 1.0" end it "does install gems from the previously requested group" do - bundle :install, :with => "debugging" + bundle :install, forgotten_command_line_options(:with => "debugging") expect(the_bundle).to include_gems "thin 1.0" bundle :install expect(the_bundle).to include_gems "thin 1.0" @@ -188,41 +187,55 @@ RSpec.describe "bundle install with groups" do end it "clears with when passed an empty list" do - bundle :install, :with => "debugging" - bundle 'install --with ""' + bundle :install, forgotten_command_line_options(:with => "debugging") + bundle :install, forgotten_command_line_options(:with => "") expect(the_bundle).not_to include_gems "thin 1.0" end - it "does remove groups from without when passed at with" do - bundle :install, :without => "emo" - bundle :install, :with => "emo" + it "does remove groups from without when passed at --with", :bundler => "< 2" do + bundle :install, forgotten_command_line_options(:without => "emo") + bundle :install, forgotten_command_line_options(:with => "emo") expect(the_bundle).to include_gems "activesupport 2.3.5" end - it "does remove groups from with when passed at without" do - bundle :install, :with => "debugging" - bundle :install, :without => "debugging" - expect(the_bundle).not_to include_gems "thin 1.0" + it "does remove groups from with when passed at --without", :bundler => "< 2" do + bundle :install, forgotten_command_line_options(:with => "debugging") + bundle :install, forgotten_command_line_options(:without => "debugging") + expect(the_bundle).not_to include_gem "thin 1.0" end - it "errors out when passing a group to with and without" do - bundle :install, :with => "emo debugging", :without => "emo" + it "errors out when passing a group to with and without via CLI flags", :bundler => "< 2" do + bundle :install, forgotten_command_line_options(:with => "emo debugging", :without => "emo") + expect(last_command).to be_failure expect(out).to include("The offending groups are: emo") end + it "allows the BUNDLE_WITH setting to override BUNDLE_WITHOUT" do + ENV["BUNDLE_WITH"] = "debugging" + + bundle! :install + expect(the_bundle).to include_gem "thin 1.0" + + ENV["BUNDLE_WITHOUT"] = "debugging" + expect(the_bundle).to include_gem "thin 1.0" + + bundle! :install + expect(the_bundle).to include_gem "thin 1.0" + end + it "can add and remove a group at the same time" do - bundle :install, :with => "debugging", :without => "emo" + bundle :install, forgotten_command_line_options(:with => "debugging", :without => "emo") expect(the_bundle).to include_gems "thin 1.0" expect(the_bundle).not_to include_gems "activesupport 2.3.5" end it "does have no effect when listing a not optional group in with" do - bundle :install, :with => "emo" + bundle :install, forgotten_command_line_options(:with => "emo") expect(the_bundle).to include_gems "activesupport 2.3.5" end it "does have no effect when listing an optional group in without" do - bundle :install, :without => "debugging" + bundle :install, forgotten_command_line_options(:without => "debugging") expect(the_bundle).not_to include_gems "thin 1.0" end end @@ -239,12 +252,12 @@ RSpec.describe "bundle install with groups" do end it "installs gems in the default group" do - bundle :install, :without => "emo lolercoaster" + bundle! :install, forgotten_command_line_options(:without => "emo lolercoaster") expect(the_bundle).to include_gems "rack 1.0.0" end it "installs the gem if any of its groups are installed" do - bundle "install --without emo" + bundle! :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.5" end @@ -265,22 +278,22 @@ RSpec.describe "bundle install with groups" do end it "installs the gem w/ option --without emo" do - bundle "install --without emo" + bundle :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).to include_gems "activesupport 2.3.5" end it "installs the gem w/ option --without lolercoaster" do - bundle "install --without lolercoaster" + bundle :install, forgotten_command_line_options(:without => "lolercoaster") expect(the_bundle).to include_gems "activesupport 2.3.5" end it "does not install the gem w/ option --without emo lolercoaster" do - bundle "install --without emo lolercoaster" + bundle :install, forgotten_command_line_options(:without => "emo lolercoaster") expect(the_bundle).not_to include_gems "activesupport 2.3.5" end it "does not install the gem w/ option --without 'emo lolercoaster'" do - bundle "install --without 'emo lolercoaster'" + bundle :install, forgotten_command_line_options(:without => "'emo lolercoaster'") expect(the_bundle).not_to include_gems "activesupport 2.3.5" end end @@ -300,12 +313,12 @@ RSpec.describe "bundle install with groups" do end it "installs gems in the default group" do - bundle :install, :without => "emo lolercoaster" + bundle! :install, forgotten_command_line_options(:without => "emo lolercoaster") expect(the_bundle).to include_gems "rack 1.0.0" end it "installs the gem if any of its groups are installed" do - bundle "install --without emo" + bundle! :install, forgotten_command_line_options(:without => "emo") expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.5" end end @@ -340,7 +353,7 @@ RSpec.describe "bundle install with groups" do before(:each) do build_repo2 system_gems "rack-0.9.1" do - install_gemfile <<-G, :without => :rack + install_gemfile <<-G, forgotten_command_line_options(:without => "rack") source "file://#{gem_repo2}" gem "rack" @@ -364,8 +377,8 @@ RSpec.describe "bundle install with groups" do it "does not hit the remote a second time" do FileUtils.rm_rf gem_repo2 - bundle "install --without rack" - expect(err).to lack_errors + bundle! :install, forgotten_command_line_options(:without => "rack").merge(:verbose => true) + expect(last_command.stdboth).not_to match(/fetching/i) end end end diff --git a/spec/bundler/install/gemfile/install_if.rb b/spec/bundler/install/gemfile/install_if.rb index b1717ad583..1319051fdb 100644 --- a/spec/bundler/install/gemfile/install_if.rb +++ b/spec/bundler/install/gemfile/install_if.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" describe "bundle install with install_if conditionals" do it "follows the install_if DSL" do diff --git a/spec/bundler/install/gemfile/lockfile_spec.rb b/spec/bundler/install/gemfile/lockfile_spec.rb new file mode 100644 index 0000000000..dc1baca6ea --- /dev/null +++ b/spec/bundler/install/gemfile/lockfile_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +RSpec.describe "bundle install with a lockfile present" do + let(:gf) { <<-G } + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + G + + subject do + install_gemfile(gf) + end + + context "gemfile evaluation" do + let(:gf) { super() + "\n\n File.open('evals', 'a') {|f| f << %(1\n) } unless ENV['BUNDLER_SPEC_NO_APPEND']" } + + context "with plugins disabled" do + before do + bundle! "config plugins false" + subject + end + + it "does not evaluate the gemfile twice" do + bundle! :install + + with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "rack 1.0.0" } + + # The first eval is from the initial install, we're testing that the + # second install doesn't double-eval + expect(bundled_app("evals").read.lines.to_a.size).to eq(2) + end + + context "when the gem is not installed" do + before { FileUtils.rm_rf ".bundle" } + + it "does not evaluate the gemfile twice" do + bundle! :install + + with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "rack 1.0.0" } + + # The first eval is from the initial install, we're testing that the + # second install doesn't double-eval + expect(bundled_app("evals").read.lines.to_a.size).to eq(2) + end + end + end + end +end diff --git a/spec/bundler/install/gemfile/path_spec.rb b/spec/bundler/install/gemfile/path_spec.rb index a1c41aebbb..f7789e7ea5 100644 --- a/spec/bundler/install/gemfile/path_spec.rb +++ b/spec/bundler/install/gemfile/path_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with explicit source paths" do - it "fetches gems" do + it "fetches gems with a global path source", :bundler => "< 2" do build_lib "foo" install_gemfile <<-G @@ -13,6 +12,18 @@ RSpec.describe "bundle install with explicit source paths" do expect(the_bundle).to include_gems("foo 1.0") end + it "fetches gems" do + build_lib "foo" + + install_gemfile <<-G + path "#{lib_path("foo-1.0")}" do + gem 'foo' + end + G + + expect(the_bundle).to include_gems("foo 1.0") + end + it "supports pinned paths" do build_lib "foo" @@ -79,7 +90,7 @@ RSpec.describe "bundle install with explicit source paths" do gem 'foo', :path => File.expand_path("../foo-1.0", __FILE__) G - bundle "install --frozen" + bundle! :install, forgotten_command_line_options(:frozen => true) expect(exitstatus).to eq(0) if exitstatus end @@ -270,8 +281,9 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - path "#{lib_path("foo-1.0")}" - gem 'foo' + path "#{lib_path("foo-1.0")}" do + gem 'foo' + end G expect(the_bundle).to include_gems "foo 1.0" @@ -591,5 +603,28 @@ RSpec.describe "bundle install with explicit source paths" do :requires => [lib_path("install_hooks.rb")] expect(out).to include("failed for foo-1.0") end + + it "loads plugins from the path gem" do + foo_file = home("foo_plugin_loaded") + bar_file = home("bar_plugin_loaded") + expect(foo_file).not_to be_file + expect(bar_file).not_to be_file + + build_lib "foo" do |s| + s.write("lib/rubygems_plugin.rb", "FileUtils.touch('#{foo_file}')") + end + + build_git "bar" do |s| + s.write("lib/rubygems_plugin.rb", "FileUtils.touch('#{bar_file}')") + end + + install_gemfile! <<-G + gem "foo", :path => "#{lib_path("foo-1.0")}" + gem "bar", :path => "#{lib_path("bar-1.0")}" + G + + expect(foo_file).to be_file + expect(bar_file).to be_file + end end end diff --git a/spec/bundler/install/gemfile/platform_spec.rb b/spec/bundler/install/gemfile/platform_spec.rb index c6eaec7ca6..d7d4e0a53c 100644 --- a/spec/bundler/install/gemfile/platform_spec.rb +++ b/spec/bundler/install/gemfile/platform_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install across platforms" do it "maintains the same lockfile if all gems are compatible across platforms" do @@ -88,7 +87,7 @@ RSpec.describe "bundle install across platforms" do expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA", "weakling 0.0.3" end - it "works with gems that have extra platform-specific runtime dependencies" do + it "works with gems that have extra platform-specific runtime dependencies", :bundler => "< 2" do simulate_platform x64_mac update_repo2 do @@ -121,12 +120,12 @@ RSpec.describe "bundle install across platforms" do gem "rack", "1.0.0" G - bundle "install --path vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") new_version = Gem::ConfigMap[:ruby_version] == "1.8" ? "1.9.1" : "1.8" FileUtils.mv(vendored_gems, bundled_app("vendor/bundle", Gem.ruby_engine, new_version)) - bundle "install --path vendor/bundle" + bundle! :install expect(vendored_gems("gems/rack-1.0.0")).to exist end end @@ -200,7 +199,7 @@ RSpec.describe "bundle install with platform conditionals" do end G - bundle :show + bundle :list expect(exitstatus).to eq(0) if exitstatus end diff --git a/spec/bundler/install/gemfile/ruby_spec.rb b/spec/bundler/install/gemfile/ruby_spec.rb index b9d9683758..24fe021fa3 100644 --- a/spec/bundler/install/gemfile/ruby_spec.rb +++ b/spec/bundler/install/gemfile/ruby_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "ruby requirement" do def locked_ruby_version diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index c5375b4abf..0b837f87a1 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with gems on multiple sources" do # repo1 is built automatically before all of the specs run @@ -29,7 +28,7 @@ RSpec.describe "bundle install with gems on multiple sources" do bundle "config major_deprecations true" end - it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first" 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.") @@ -59,7 +58,7 @@ RSpec.describe "bundle install with gems on multiple sources" do bundle "config major_deprecations true" end - it "warns about ambiguous gems, but installs anyway" do + it "warns about ambiguous gems, but installs anyway", :bundler => "< 2" do bundle :install expect(out).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") @@ -79,6 +78,10 @@ RSpec.describe "bundle install with gems on multiple sources" do build_gem "rack", "1.0.0" do |s| s.write "lib/rack.rb", "RACK = 'FAIL'" end + + build_gem "rack-obama" do |s| + s.add_dependency "rack" + end end gemfile <<-G @@ -92,21 +95,20 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "installs the gems without any warning" do - bundle :install + bundle! :install expect(out).not_to include("Warning") expect(the_bundle).to include_gems("rack-obama 1.0.0") expect(the_bundle).to include_gems("rack 1.0.0", :source => "remote1") end it "can cache and deploy" do - bundle :package + bundle! :package expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/rack-obama-1.0.gem")).to exist - bundle "install --deployment" + bundle! :install, forgotten_command_line_options(:deployment => true) - expect(exitstatus).to eq(0) if exitstatus expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0") end end @@ -119,6 +121,10 @@ RSpec.describe "bundle install with gems on multiple sources" do build_gem "rack", "1.0.0" do |s| s.write "lib/rack.rb", "RACK = 'FAIL'" end + + build_gem "rack-obama" do |s| + s.add_dependency "rack" + end end gemfile <<-G @@ -135,7 +141,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end end - context "with an indirect dependency" do + context "when a pinned gem has an indirect dependency" do before do build_repo gem_repo3 do build_gem "depends_on_rack", "1.0.1" do |s| @@ -181,10 +187,27 @@ RSpec.describe "bundle install with gems on multiple sources" do end end - it "installs from the same source without any warning" do - bundle :install - expect(out).not_to include("Warning") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") + context "when lockfile_uses_separate_rubygems_sources is set" do + before do + bundle! "config lockfile_uses_separate_rubygems_sources true" + bundle! "config disable_multisource true" + end + + it "installs from the same source without any 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") + + # when there is already a lock file, and the gems are missing, so try again + 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 end end @@ -225,7 +248,7 @@ RSpec.describe "bundle install with gems on multiple sources" do G end - it "installs from the other source and warns about ambiguous gems" do + it "installs from the other source and warns about ambiguous gems", :bundler => "< 2" do bundle "config major_deprecations true" bundle :install expect(out).to have_major_deprecation a_string_including("Your Gemfile contains multiple primary sources.") @@ -253,7 +276,7 @@ RSpec.describe "bundle install with gems on multiple sources" do G end - it "installs the dependency from the pinned source without warning" 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.") @@ -271,6 +294,86 @@ RSpec.describe "bundle install with gems on multiple sources" do end end + context "when a top-level gem has an indirect dependency" do + context "when lockfile_uses_separate_rubygems_sources is set" do + before do + bundle! "config lockfile_uses_separate_rubygems_sources true" + bundle! "config disable_multisource true" + end + + before do + build_repo gem_repo2 do + build_gem "depends_on_rack", "1.0.1" do |s| + s.add_dependency "rack" + end + end + + build_repo gem_repo3 do + build_gem "unrelated_gem", "1.0.0" + end + + gemfile <<-G + source "file://#{gem_repo2}" + + gem "depends_on_rack" + + source "file://#{gem_repo3}" do + gem "unrelated_gem" + end + G + end + + context "and the dependency is only in the top-level source" do + before do + update_repo gem_repo2 do + build_gem "rack", "1.0.0" + end + end + + it "installs all gems without warning" do + bundle :install + expect(out).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 + + context "and the dependency is only in a pinned source" do + before do + update_repo gem_repo3 do + build_gem "rack", "1.0.0" do |s| + s.write "lib/rack.rb", "RACK = 'FAIL'" + end + end + end + + 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") + end + end + + context "and the dependency is in both the top-level and a pinned source" do + before do + update_repo gem_repo2 do + build_gem "rack", "1.0.0" + end + + update_repo gem_repo3 do + build_gem "rack", "1.0.0" do |s| + s.write "lib/rack.rb", "RACK = 'FAIL'" + end + end + end + + it "installs the dependency from the top-level source without warning" do + bundle :install + expect(out).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 + end + end + context "with a gem that is only found in the wrong source" do before do build_repo gem_repo3 do @@ -291,7 +394,7 @@ RSpec.describe "bundle install with gems on multiple sources" do context "with an existing lockfile" do before do - system_gems "rack-0.9.1", "rack-1.0.0" + system_gems "rack-0.9.1", "rack-1.0.0", :path => :bundle_path lockfile <<-L GEM @@ -394,7 +497,7 @@ RSpec.describe "bundle install with gems on multiple sources" do rack L - bundle "install --path ../gems/system" + bundle! :install, forgotten_command_line_options(:path => "../gems/system") # 4. Then we add some new versions... update_repo4 do @@ -413,8 +516,7 @@ RSpec.describe "bundle install with gems on multiple sources" do G # 6. Which should update foo to 0.2, but not the (locked) bar 0.1 - expect(the_bundle).to include_gems("foo 0.2") - expect(the_bundle).to include_gems("bar 0.1") + expect(the_bundle).to include_gems("foo 0.2", "bar 0.1") end end diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index cc6c82c0ff..9c725416d5 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with specific_platform enabled" do before do @@ -61,10 +60,10 @@ RSpec.describe "bundle install with specific_platform enabled" do install_gemfile!(google_protobuf) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gem("google-protobuf 3.0.0.alpha.5.0.5.1 universal-darwin") - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w( + expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ google-protobuf-3.0.0.alpha.5.0.5.1 google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin - )) + ]) end it "caches both the universal-darwin and ruby gems when --all-platforms is passed" do @@ -93,11 +92,11 @@ RSpec.describe "bundle install with specific_platform enabled" do bundle! "lock --add-platform=#{x64_mingw}" expect(the_bundle.locked_gems.platforms).to eq([rb, x64_mingw, pl("x86_64-darwin-15")]) - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w( + expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ google-protobuf-3.0.0.alpha.5.0.5.1 google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin google-protobuf-3.0.0.alpha.5.0.5.1-x64-mingw32 - )) + ]) end it "falls back on plain ruby when that version doesnt have a platform-specific gem" do @@ -105,10 +104,10 @@ RSpec.describe "bundle install with specific_platform enabled" do bundle! "lock --add-platform=#{java}" expect(the_bundle.locked_gems.platforms).to eq([java, rb, pl("x86_64-darwin-15")]) - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w( + expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ google-protobuf-3.0.0.alpha.5.0.5.1 google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin - )) + ]) end end end diff --git a/spec/bundler/install/gemfile_spec.rb b/spec/bundler/install/gemfile_spec.rb index bc49053081..945d9f485d 100644 --- a/spec/bundler/install/gemfile_spec.rb +++ b/spec/bundler/install/gemfile_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do context "with duplicated gems" do @@ -37,7 +36,7 @@ RSpec.describe "bundle install" do end it "uses the gemfile to install" do bundle "install" - bundle "show" + bundle "list" expect(out).to include("rack (1.0.0)") end @@ -45,7 +44,7 @@ RSpec.describe "bundle install" do bundled_app("subdir").mkpath Dir.chdir(bundled_app("subdir")) do bundle "install" - bundle "show" + bundle "list" expect(out).to include("rack (1.0.0)") end @@ -67,6 +66,22 @@ RSpec.describe "bundle install" do end end + context "with prefer_gems_rb set" do + before { bundle! "config prefer_gems_rb true" } + + it "prefers gems.rb to Gemfile" do + create_file("gems.rb", "gem 'bundler'") + create_file("Gemfile", "raise 'wrong Gemfile!'") + + bundle! :install + + expect(bundled_app("gems.rb")).to be_file + expect(bundled_app("Gemfile.lock")).not_to be_file + + expect(the_bundle).to include_gem "bundler #{Bundler::VERSION}" + end + end + context "with engine specified in symbol" do it "does not raise any error parsing Gemfile" do simulate_ruby_version "2.3.0" do diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index 825185c82e..07700f5030 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "compact index api" do let(:source_hostname) { "localgemserver.test" } @@ -61,7 +60,7 @@ RSpec.describe "compact index api" do # can't use `include_gems` here since the `require` will conflict on a # case-insensitive FS run! "Bundler.require; puts Gem.loaded_specs.values_at('rack', 'Rack').map(&:full_name)" - expect(out).to eq("rack-1.0\nRack-0.1") + expect(last_command.stdout).to eq("rack-1.0\nRack-0.1") end it "should handle multiple gem dependencies on the same gem" do @@ -81,7 +80,7 @@ RSpec.describe "compact index api" do G bundle! :install, :artifice => "compact_index" - bundle "install --deployment", :artifice => "compact_index" + bundle! :install, forgotten_command_line_options(:deployment => true, :path => "vendor/bundle").merge(:artifice => "compact_index") expect(out).to include("Fetching gem metadata from #{source_uri}") expect(the_bundle).to include_gems "rack 1.0.0" end @@ -130,9 +129,8 @@ RSpec.describe "compact index api" do G bundle "install", :artifice => "compact_index" - bundle "install --deployment", :artifice => "compact_index" + bundle! :install, forgotten_command_line_options(:deployment => true).merge(:artifice => "compact_index") - expect(exitstatus).to eq(0) if exitstatus expect(the_bundle).to include_gems("foo 1.0") end @@ -175,7 +173,7 @@ The checksum of /versions does not match the checksum provided by the server! So end it "falls back when the user's home directory does not exist or is not writable" do - ENV["HOME"] = nil + ENV["HOME"] = tmp("missing_home").to_s gemfile <<-G source "#{source_uri}" @@ -249,13 +247,29 @@ The checksum of /versions does not match the checksum provided by the server! So gem "rack" G - bundle "update --full-index", :artifice => "compact_index" + bundle! "update --full-index", :artifice => "compact_index", :all => bundle_update_requires_all? expect(out).to include("Fetching source index from #{source_uri}") expect(the_bundle).to include_gems "rack 1.0.0" end end - it "fetches again when more dependencies are found in subsequent sources" do + it "does not double check for gems that are only installed locally" do + system_gems %w[rack-1.0.0 thin-1.0 net_a-1.0] + bundle! "config --local path.system true" + ENV["BUNDLER_SPEC_ALL_REQUESTS"] = strip_whitespace(<<-EOS).strip + #{source_uri}/versions + #{source_uri}/info/rack + EOS + + install_gemfile! <<-G, :artifice => "compact_index", :verbose => true + source "#{source_uri}" + gem "rack" + G + + expect(last_command.stdboth).not_to include "Double checking" + end + + it "fetches again when more dependencies are found in subsequent sources", :bundler => "< 2" do build_repo2 do build_gem "back_deps" do |s| s.add_dependency "foo" @@ -270,7 +284,25 @@ The checksum of /versions does not match the checksum provided by the server! So G bundle! :install, :artifice => "compact_index_extra" - expect(the_bundle).to include_gems "back_deps 1.0" + expect(the_bundle).to include_gems "back_deps 1.0", "foo 1.0" + end + + it "fetches again when more dependencies are found in subsequent sources with source blocks" do + build_repo2 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] + end + + install_gemfile! <<-G, :artifice => "compact_index_extra", :verbose => true + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + expect(the_bundle).to include_gems "back_deps 1.0", "foo 1.0" end it "fetches gem versions even when those gems are already installed" do @@ -296,7 +328,7 @@ The checksum of /versions does not match the checksum provided by the server! So expect(the_bundle).to include_gems "rack 1.2" end - it "considers all possible versions of dependencies from all api gem sources" do + it "considers all possible versions of dependencies from all api gem sources", :bundler => "< 2" do # In this scenario, the gem "somegem" only exists in repo4. It depends on specific version of activesupport that # exists only in repo1. There happens also be a version of activesupport in repo4, but not the one that version 1.0.0 # of somegem wants. This test makes sure that bundler actually finds version 1.2.3 of active support in the other @@ -320,6 +352,31 @@ The checksum of /versions does not match the checksum provided by the server! So expect(the_bundle).to include_gems "activesupport 1.2.3" end + it "considers all possible versions of dependencies from all api gem sources when using blocks", :bundler => "< 2" do + # In this scenario, the gem "somegem" only exists in repo4. It depends on specific version of activesupport that + # exists only in repo1. There happens also be a version of activesupport in repo4, but not the one that version 1.0.0 + # of somegem wants. This test makes sure that bundler actually finds version 1.2.3 of active support in the other + # repo and installs it. + build_repo4 do + build_gem "activesupport", "1.2.0" + build_gem "somegem", "1.0.0" do |s| + s.add_dependency "activesupport", "1.2.3" # This version exists only in repo1 + end + end + + gemfile <<-G + source "#{source_uri}" + source "#{source_uri}/extra" do + gem 'somegem', '1.0.0' + end + G + + bundle! :install, :artifice => "compact_index_extra_api" + + expect(the_bundle).to include_gems "somegem 1.0.0" + expect(the_bundle).to include_gems "activesupport 1.2.3" + end + it "prints API output properly with back deps" do build_repo2 do build_gem "back_deps" do |s| @@ -330,8 +387,9 @@ The checksum of /versions does not match the checksum provided by the server! So gemfile <<-G source "#{source_uri}" - source "#{source_uri}/extra" - gem "back_deps" + source "#{source_uri}/extra" do + gem "back_deps" + end G bundle! :install, :artifice => "compact_index_extra" @@ -356,14 +414,39 @@ The checksum of /versions does not match the checksum provided by the server! So gemfile <<-G source "#{source_uri}" - source "#{source_uri}/extra" - gem "back_deps" + source "#{source_uri}/extra" do + gem "back_deps" + end G bundle! :install, :artifice => "compact_index_extra_missing" expect(the_bundle).to include_gems "back_deps 1.0" end + it "does not fetch every spec if the index of gems is large when doing back deps & everything is the compact index" do + build_repo4 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + build_gem "missing" + # need to hit the limit + 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| + build_gem "gem#{i}" + end + + FileUtils.rm_rf Dir[gem_repo4("gems/foo-*.gem")] + end + + install_gemfile! <<-G, :artifice => "compact_index_extra_api_missing" + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + expect(the_bundle).to include_gem "back_deps 1.0" + end + it "uses the endpoint if all sources support it" do gemfile <<-G source "#{source_uri}" @@ -375,7 +458,7 @@ The checksum of /versions does not match the checksum provided by the server! So expect(the_bundle).to include_gems "foo 1.0" end - it "fetches again when more dependencies are found in subsequent sources using --deployment" do + it "fetches again when more dependencies are found in subsequent sources using --deployment", :bundler => "< 2" do build_repo2 do build_gem "back_deps" do |s| s.add_dependency "foo" @@ -395,6 +478,27 @@ The checksum of /versions does not match the checksum provided by the server! So expect(the_bundle).to include_gems "back_deps 1.0" end + it "fetches again when more dependencies are found in subsequent sources using --deployment with blocks" do + build_repo2 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] + end + + gemfile <<-G + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + bundle! :install, :artifice => "compact_index_extra" + + bundle "install --deployment", :artifice => "compact_index_extra" + expect(the_bundle).to include_gems "back_deps 1.0" + end + it "does not refetch if the only unmet dependency is bundler" do gemfile <<-G source "#{source_uri}" @@ -418,7 +522,7 @@ The checksum of /versions does not match the checksum provided by the server! So expect(the_bundle).to include_gems "rails 2.3.2" end - it "installs the binstubs" do + it "installs the binstubs", :bundler => "< 2" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -430,7 +534,7 @@ The checksum of /versions does not match the checksum provided by the server! So expect(out).to eq("1.0.0") end - it "installs the bins when using --path and uses autoclean" do + it "installs the bins when using --path and uses autoclean", :bundler => "< 2" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -441,7 +545,7 @@ The checksum of /versions does not match the checksum provided by the server! So expect(vendored_gems("bin/rackup")).to exist end - it "installs the bins when using --path and uses bundle clean" do + it "installs the bins when using --path and uses bundle clean", :bundler => "< 2" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -516,7 +620,7 @@ The checksum of /versions does not match the checksum provided by the server! So expect(out).not_to include("#{user}:#{password}") end - it "strips http basic auth creds when warning about ambiguous sources" do + it "strips http basic auth creds when warning about ambiguous sources", :bundler => "< 2" do gemfile <<-G source "#{basic_auth_source_uri}" source "file://#{gem_repo1}" @@ -613,7 +717,7 @@ The checksum of /versions does not match the checksum provided by the server! So end end - context "when ruby is compiled without openssl" do + context "when ruby is compiled without openssl", :ruby_repo do before do # Install a monkeypatch that reproduces the effects of openssl being # missing when the fetcher runs, as happens in real life. The reason @@ -640,7 +744,7 @@ The checksum of /versions does not match the checksum provided by the server! So context "when SSL certificate verification fails" do it "explains what happened" do # Install a monkeypatch that reproduces the effects of openssl raising - # a certificate validation error when Rubygems tries to connect. + # a certificate validation error when RubyGems tries to connect. gemfile <<-G class Net::HTTP def start @@ -741,7 +845,7 @@ The checksum of /versions does not match the checksum provided by the server! So and include("The checksum for the downloaded `rack-1.0.0.gem` does not match the checksum given by the server."). and include("This means the contents of the downloaded gem is different from what was uploaded to the server, and could be a potential security issue."). and include("To resolve this issue:"). - and include("1. delete the downloaded gem located at: `#{system_gem_path}/gems/rack-1.0.0/rack-1.0.0.gem`"). + and include("1. delete the downloaded gem located at: `#{default_bundle_path}/gems/rack-1.0.0/rack-1.0.0.gem`"). and include("2. run `bundle install`"). and include("If you wish to continue installing the downloaded gem, and are certain it does not pose a security issue despite the mismatching checksum, do the following:"). and include("1. run `bundle config disable_checksum_validation true` to turn off checksum verification"). diff --git a/spec/bundler/install/gems/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_spec.rb index d2de0d358b..fe696f38c3 100644 --- a/spec/bundler/install/gems/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "gemcutter's dependency API" do let(:source_hostname) { "localgemserver.test" } @@ -61,7 +60,7 @@ RSpec.describe "gemcutter's dependency API" do G bundle :install, :artifice => "endpoint" - bundle "install --deployment", :artifice => "endpoint" + bundle! :install, forgotten_command_line_options(:deployment => true, :path => "vendor/bundle").merge(:artifice => "endpoint") expect(out).to include("Fetching gem metadata from #{source_uri}") expect(the_bundle).to include_gems "rack 1.0.0" end @@ -110,9 +109,8 @@ RSpec.describe "gemcutter's dependency API" do G bundle "install", :artifice => "endpoint" - bundle "install --deployment", :artifice => "endpoint" + bundle! :install, forgotten_command_line_options(:deployment => true).merge(:artifice => "endpoint") - expect(exitstatus).to eq(0) if exitstatus expect(the_bundle).to include_gems("foo 1.0") end @@ -239,13 +237,13 @@ RSpec.describe "gemcutter's dependency API" do gem "rack" G - bundle "update --full-index", :artifice => "endpoint" + bundle! "update --full-index", :artifice => "endpoint", :all => bundle_update_requires_all? expect(out).to include("Fetching source index from #{source_uri}") expect(the_bundle).to include_gems "rack 1.0.0" end end - it "fetches again when more dependencies are found in subsequent sources" do + it "fetches again when more dependencies are found in subsequent sources", :bundler => "< 2" do build_repo2 do build_gem "back_deps" do |s| s.add_dependency "foo" @@ -260,7 +258,26 @@ RSpec.describe "gemcutter's dependency API" do G bundle :install, :artifice => "endpoint_extra" - expect(the_bundle).to include_gems "back_deps 1.0" + expect(the_bundle).to include_gems "back_deps 1.0", "foo 1.0" + end + + it "fetches again when more dependencies are found in subsequent sources using blocks" do + build_repo2 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] + end + + gemfile <<-G + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + bundle :install, :artifice => "endpoint_extra" + expect(the_bundle).to include_gems "back_deps 1.0", "foo 1.0" end it "fetches gem versions even when those gems are already installed" do @@ -285,7 +302,7 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "rack 1.2" end - it "considers all possible versions of dependencies from all api gem sources" do + it "considers all possible versions of dependencies from all api gem sources", :bundler => "< 2" do # In this scenario, the gem "somegem" only exists in repo4. It depends on specific version of activesupport that # exists only in repo1. There happens also be a version of activesupport in repo4, but not the one that version 1.0.0 # of somegem wants. This test makes sure that bundler actually finds version 1.2.3 of active support in the other @@ -303,6 +320,31 @@ RSpec.describe "gemcutter's dependency API" do gem 'somegem', '1.0.0' G + bundle! :install, :artifice => "endpoint_extra_api" + + expect(the_bundle).to include_gems "somegem 1.0.0" + expect(the_bundle).to include_gems "activesupport 1.2.3" + end + + it "considers all possible versions of dependencies from all api gem sources using blocks" do + # In this scenario, the gem "somegem" only exists in repo4. It depends on specific version of activesupport that + # exists only in repo1. There happens also be a version of activesupport in repo4, but not the one that version 1.0.0 + # of somegem wants. This test makes sure that bundler actually finds version 1.2.3 of active support in the other + # repo and installs it. + build_repo4 do + build_gem "activesupport", "1.2.0" + build_gem "somegem", "1.0.0" do |s| + s.add_dependency "activesupport", "1.2.3" # This version exists only in repo1 + end + end + + gemfile <<-G + source "#{source_uri}" + source "#{source_uri}/extra" do + gem 'somegem', '1.0.0' + end + G + bundle :install, :artifice => "endpoint_extra_api" expect(the_bundle).to include_gems "somegem 1.0.0" @@ -319,17 +361,18 @@ RSpec.describe "gemcutter's dependency API" do gemfile <<-G source "#{source_uri}" - source "#{source_uri}/extra" - gem "back_deps" + source "#{source_uri}/extra" do + gem "back_deps" + end G bundle :install, :artifice => "endpoint_extra" - expect(out).to include("Fetching gem metadata from http://localgemserver.test/..") + expect(out).to include("Fetching gem metadata from http://localgemserver.test/.") expect(out).to include("Fetching source index from http://localgemserver.test/extra") end - it "does not fetch every spec if the index of gems is large when doing back deps" do + it "does not fetch every spec if the index of gems is large when doing back deps", :bundler => "< 2" do build_repo2 do build_gem "back_deps" do |s| s.add_dependency "foo" @@ -353,6 +396,31 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "back_deps 1.0" end + it "does not fetch every spec if the index of gems is large when doing back deps using blocks" do + build_repo2 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + build_gem "missing" + # need to hit the limit + 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| + build_gem "gem#{i}" + end + + FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] + end + + gemfile <<-G + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + bundle :install, :artifice => "endpoint_extra_missing" + expect(the_bundle).to include_gems "back_deps 1.0" + end + it "uses the endpoint if all sources support it" do gemfile <<-G source "#{source_uri}" @@ -364,7 +432,7 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "foo 1.0" end - it "fetches again when more dependencies are found in subsequent sources using --deployment" do + it "fetches again when more dependencies are found in subsequent sources using --deployment", :bundler => "< 2" do build_repo2 do build_gem "back_deps" do |s| s.add_dependency "foo" @@ -384,6 +452,27 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "back_deps 1.0" end + it "fetches again when more dependencies are found in subsequent sources using --deployment with blocks" do + build_repo2 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] + end + + gemfile <<-G + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + bundle :install, :artifice => "endpoint_extra" + + bundle "install --deployment", :artifice => "endpoint_extra" + expect(the_bundle).to include_gems "back_deps 1.0" + end + it "does not refetch if the only unmet dependency is bundler" do gemfile <<-G source "#{source_uri}" @@ -407,7 +496,7 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "rails 2.3.2" end - it "installs the binstubs" do + it "installs the binstubs", :bundler => "< 2" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -419,7 +508,7 @@ RSpec.describe "gemcutter's dependency API" do expect(out).to eq("1.0.0") end - it "installs the bins when using --path and uses autoclean" do + it "installs the bins when using --path and uses autoclean", :bundler => "< 2" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -430,7 +519,7 @@ RSpec.describe "gemcutter's dependency API" do expect(vendored_gems("bin/rackup")).to exist end - it "installs the bins when using --path and uses bundle clean" do + it "installs the bins when using --path and uses bundle clean", :bundler => "< 2" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -505,7 +594,7 @@ RSpec.describe "gemcutter's dependency API" do expect(out).not_to include("#{user}:#{password}") end - it "strips http basic auth creds when warning about ambiguous sources" do + it "strips http basic auth creds when warning about ambiguous sources", :bundler => "< 2" do gemfile <<-G source "#{basic_auth_source_uri}" source "file://#{gem_repo1}" @@ -602,7 +691,7 @@ RSpec.describe "gemcutter's dependency API" do end end - context "when ruby is compiled without openssl" do + context "when ruby is compiled without openssl", :ruby_repo do before do # Install a monkeypatch that reproduces the effects of openssl being # missing when the fetcher runs, as happens in real life. The reason @@ -629,7 +718,7 @@ RSpec.describe "gemcutter's dependency API" do context "when SSL certificate verification fails" do it "explains what happened" do # Install a monkeypatch that reproduces the effects of openssl raising - # a certificate validation error when Rubygems tries to connect. + # a certificate validation error when RubyGems tries to connect. gemfile <<-G class Net::HTTP def start diff --git a/spec/bundler/install/gems/env_spec.rb b/spec/bundler/install/gems/env_spec.rb index 9b1d8e5424..0dccbbfd24 100644 --- a/spec/bundler/install/gems/env_spec.rb +++ b/spec/bundler/install/gems/env_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with ENV conditionals" do describe "when just setting an ENV key as a string" do diff --git a/spec/bundler/install/gems/flex_spec.rb b/spec/bundler/install/gems/flex_spec.rb index 2c2d3c16a1..f6af806154 100644 --- a/spec/bundler/install/gems/flex_spec.rb +++ b/spec/bundler/install/gems/flex_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle flex_install" do it "installs the gems as expected" do @@ -194,8 +193,6 @@ RSpec.describe "bundle flex_install" do it "suggests bundle update when the Gemfile requires different versions than the lock" do nice_error = <<-E.strip.gsub(/^ {8}/, "") - Fetching source index from file:#{gem_repo2}/ - Resolving dependencies... Bundler could not find compatible versions for gem "rack": In snapshot (Gemfile.lock): rack (= 0.9.1) @@ -212,7 +209,7 @@ RSpec.describe "bundle flex_install" do E bundle :install, :retry => 0 - expect(out).to eq(nice_error) + expect(last_command.bundler_err).to end_with(nice_error) end end @@ -247,13 +244,13 @@ RSpec.describe "bundle flex_install" do end describe "when adding a new source" do - it "updates the lockfile" do + it "updates the lockfile", :bundler => "< 2" do build_repo2 - install_gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" G - install_gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" source "file://#{gem_repo2}" gem "rack" @@ -276,6 +273,41 @@ RSpec.describe "bundle flex_install" do #{Bundler::VERSION} L end + + it "updates the lockfile", :bundler => "2" do + build_repo2 + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + install_gemfile! <<-G + source "file://#{gem_repo1}" + source "file://#{gem_repo2}" do + end + gem "rack" + G + + lockfile_should_be <<-L + GEM + remote: file:#{gem_repo1}/ + specs: + rack (1.0.0) + + GEM + remote: file:#{gem_repo2}/ + specs: + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + #{Bundler::VERSION} + L + end end # This was written to test github issue #636 diff --git a/spec/bundler/install/gems/mirror_spec.rb b/spec/bundler/install/gems/mirror_spec.rb index 798156fb12..a8516a28c3 100644 --- a/spec/bundler/install/gems/mirror_spec.rb +++ b/spec/bundler/install/gems/mirror_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with a mirror configured" do describe "when the mirror does not match the gem source" do diff --git a/spec/bundler/install/gems/native_extensions_spec.rb b/spec/bundler/install/gems/native_extensions_spec.rb index dcf67e976e..ea616f60d3 100644 --- a/spec/bundler/install/gems/native_extensions_spec.rb +++ b/spec/bundler/install/gems/native_extensions_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "installing a gem with native extensions", :ruby_repo do it "installs" do @@ -84,7 +83,6 @@ RSpec.describe "installing a gem with native extensions", :ruby_repo do G expect(out).not_to include("extconf.rb failed") - expect(out).to include("Using c_extension 1.0") run! "Bundler.require; puts CExtension.new.its_true" expect(out).to eq("true") diff --git a/spec/bundler/install/gems/post_install_spec.rb b/spec/bundler/install/gems/post_install_spec.rb index c3ea3e7c51..c6e348fb65 100644 --- a/spec/bundler/install/gems/post_install_spec.rb +++ b/spec/bundler/install/gems/post_install_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do context "with gem sources" do diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index 7a341fd14f..23e3caaefc 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with install-time dependencies" do it "installs gems with implicit rake dependencies", :ruby_repo do @@ -92,8 +91,10 @@ RSpec.describe "bundle install with install-time dependencies" do bundle :install, :env => { "DEBUG_RESOLVER_TREE" => "1" } - expect(err).to include(" net_b") - expect(err).to include(" net_build_extensions (1.0)") + expect(err).to include(" net_b"). + and include("Starting resolution"). + and include("Finished resolution"). + and include("Attempting to activate") end end end @@ -141,9 +142,6 @@ RSpec.describe "bundle install with install-time dependencies" do expect(out).to_not include("Gem::InstallError: require_ruby requires Ruby version > 9000") nice_error = strip_whitespace(<<-E).strip - Fetching gem metadata from http://localgemserver.test/. - Fetching version metadata from http://localgemserver.test/ - Resolving dependencies... Bundler could not find compatible versions for gem "ruby\0": In Gemfile: ruby\0 (#{error_message_requirement}) @@ -151,9 +149,10 @@ RSpec.describe "bundle install with install-time dependencies" do require_ruby was resolved to 1.0, which depends on ruby\0 (> 9000) - Could not find gem 'ruby\0 (> 9000)', which is required by gem 'require_ruby', in any of the sources. + Could not find gem 'ruby\0 (> 9000)', which is required by gem 'require_ruby', in any of the relevant sources: + the local ruby installation E - expect(out).to eq(nice_error) + expect(last_command.bundler_err).to end_with(nice_error) end end diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index 9a79a05b32..551f07848d 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.shared_examples "bundle install --standalone" do shared_examples "common functionality" do @@ -51,10 +50,11 @@ RSpec.shared_examples "bundle install --standalone" do describe "with simple gems" do before do - install_gemfile <<-G, :standalone => true + gemfile <<-G source "file://#{gem_repo1}" gem "rails" G + bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) end let(:expected_gems) do @@ -69,7 +69,7 @@ RSpec.shared_examples "bundle install --standalone" do describe "with gems with native extension", :ruby_repo do before do - install_gemfile <<-G, :standalone => true + install_gemfile <<-G, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) source "file://#{gem_repo1}" gem "very_simple_binary" G @@ -101,7 +101,7 @@ RSpec.shared_examples "bundle install --standalone" do end G end - install_gemfile <<-G, :standalone => true + install_gemfile <<-G, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) gem "bar", :git => "#{lib_path("bar-1.0")}" G end @@ -116,11 +116,12 @@ RSpec.shared_examples "bundle install --standalone" do before do build_git "devise", "1.0" - install_gemfile <<-G, :standalone => true + gemfile <<-G source "file://#{gem_repo1}" gem "rails" gem "devise", :git => "#{lib_path("devise-1.0")}" G + bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) end let(:expected_gems) do @@ -138,7 +139,7 @@ RSpec.shared_examples "bundle install --standalone" do before do build_git "devise", "1.0" - install_gemfile <<-G, :standalone => true + gemfile <<-G source "file://#{gem_repo1}" gem "rails" @@ -147,6 +148,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rack-test" end G + bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) end let(:expected_gems) do @@ -159,7 +161,7 @@ RSpec.shared_examples "bundle install --standalone" do include_examples "common functionality" it "allows creating a standalone file with limited groups" do - bundle "install --standalone default" + bundle! "install", forgotten_command_line_options(:path => "bundle").merge(:standalone => "default") Dir.chdir(bundled_app) do load_error_ruby <<-RUBY, "spec", :no_lib => true @@ -172,12 +174,12 @@ RSpec.shared_examples "bundle install --standalone" do RUBY end - expect(out).to eq("2.3.2") - expect(err).to eq("ZOMG LOAD ERROR") + expect(last_command.stdout).to eq("2.3.2") + expect(last_command.stderr).to eq("ZOMG LOAD ERROR") end it "allows --without to limit the groups used in a standalone" do - bundle "install --standalone --without test" + bundle! :install, forgotten_command_line_options(:path => "bundle", :without => "test").merge(:standalone => true) Dir.chdir(bundled_app) do load_error_ruby <<-RUBY, "spec", :no_lib => true @@ -190,12 +192,12 @@ RSpec.shared_examples "bundle install --standalone" do RUBY end - expect(out).to eq("2.3.2") - expect(err).to eq("ZOMG LOAD ERROR") + expect(last_command.stdout).to eq("2.3.2") + expect(last_command.stderr).to eq("ZOMG LOAD ERROR") end it "allows --path to change the location of the standalone bundle" do - bundle "install --standalone --path path/to/bundle" + bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) Dir.chdir(bundled_app) do ruby <<-RUBY, :no_lib => true @@ -207,12 +209,12 @@ RSpec.shared_examples "bundle install --standalone" do RUBY end - expect(out).to eq("2.3.2") + expect(last_command.stdout).to eq("2.3.2") end it "allows remembered --without to limit the groups used in a standalone" do - bundle "install --without test" - bundle "install --standalone" + bundle! :install, forgotten_command_line_options(:without => "test") + bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) Dir.chdir(bundled_app) do load_error_ruby <<-RUBY, "spec", :no_lib => true @@ -225,8 +227,8 @@ RSpec.shared_examples "bundle install --standalone" do RUBY end - expect(out).to eq("2.3.2") - expect(err).to eq("ZOMG LOAD ERROR") + expect(last_command.stdout).to eq("2.3.2") + expect(last_command.stderr).to eq("ZOMG LOAD ERROR") end end @@ -239,7 +241,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{source_uri}" gem "rails" G - bundle "install --standalone", :artifice => "endpoint" + bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true, :artifice => "endpoint") end let(:expected_gems) do @@ -253,12 +255,13 @@ RSpec.shared_examples "bundle install --standalone" do end end - describe "with --binstubs" do + describe "with --binstubs", :bundler => "< 2" do before do - install_gemfile <<-G, :standalone => true, :binstubs => true + gemfile <<-G source "file://#{gem_repo1}" gem "rails" G + bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true, :binstubs => true) end let(:expected_gems) do diff --git a/spec/bundler/install/gems/sudo_spec.rb b/spec/bundler/install/gems/sudo_spec.rb index 13abffc14e..ae94eee9c6 100644 --- a/spec/bundler/install/gems/sudo_spec.rb +++ b/spec/bundler/install/gems/sudo_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "when using sudo", :sudo => true do describe "and BUNDLE_PATH is writable" do context "but BUNDLE_PATH/build_info is not writable" do before do + bundle! "config path.system true" subdir = system_gem_path("cache") subdir.mkpath sudo "chmod u-w #{subdir}" @@ -25,6 +25,7 @@ RSpec.describe "when using sudo", :sudo => true do describe "and GEM_HOME is owned by root" do before :each do + bundle! "config path.system true" chown_system_gems_to_root end @@ -83,7 +84,7 @@ RSpec.describe "when using sudo", :sudo => true do expect(the_bundle).to include_gems "rack 1.0" end - it "installs extensions/ compiled by Rubygems 2.2", :rubygems => "2.2" do + it "installs extensions/ compiled by RubyGems 2.2", :rubygems => "2.2" do install_gemfile <<-G source "file://#{gem_repo1}" gem "very_simple_binary" @@ -128,6 +129,7 @@ RSpec.describe "when using sudo", :sudo => true do describe "and GEM_HOME is not writable" do it "installs" do + bundle! "config path.system true" gem_home = tmp("sudo_gem_home") sudo "mkdir -p #{gem_home}" sudo "chmod ugo-w #{gem_home}" @@ -162,16 +164,9 @@ RSpec.describe "when using sudo", :sudo => true do end end - context "when silence_root_warning is passed as an option" do - it "skips the warning" do - bundle :install, :sudo => true, :silence_root_warning => true - expect(out).to_not include(warning) - end - end - context "when silence_root_warning = false" do it "warns against that" do - bundle :install, :sudo => true, :silence_root_warning => false + bundle :install, :sudo => true, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => "false" } expect(out).to include(warning) end end diff --git a/spec/bundler/install/gems/win32_spec.rb b/spec/bundler/install/gems/win32_spec.rb index cdad9a8821..ad758b94fa 100644 --- a/spec/bundler/install/gems/win32_spec.rb +++ b/spec/bundler/install/gems/win32_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install with win32-generated lockfile" do it "should read lockfile" do diff --git a/spec/bundler/install/gemspecs_spec.rb b/spec/bundler/install/gemspecs_spec.rb index 97eaf149c1..0c1ed99097 100644 --- a/spec/bundler/install/gemspecs_spec.rb +++ b/spec/bundler/install/gemspecs_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do describe "when a gem has a YAML gemspec" do @@ -34,8 +33,8 @@ RSpec.describe "bundle install" do gem 'rack' G - FileUtils.mkdir_p "#{tmp}/gems/system/specifications" - File.open("#{tmp}/gems/system/specifications/rack-1.0.0.gemspec", "w+") do |f| + FileUtils.mkdir_p "#{default_bundle_path}/specifications" + File.open("#{default_bundle_path}/specifications/rack-1.0.0.gemspec", "w+") do |f| spec = Gem::Specification.new do |s| s.name = "rack" s.version = "1.0.0" diff --git a/spec/bundler/install/git_spec.rb b/spec/bundler/install/git_spec.rb index 04f2380b45..6ae718c2a4 100644 --- a/spec/bundler/install/git_spec.rb +++ b/spec/bundler/install/git_spec.rb @@ -1,21 +1,20 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do context "git sources" do - it "displays the revision hash of the gem repository" do + it "displays the revision hash of the gem repository", :bundler => "< 2" do build_git "foo", "1.0", :path => lib_path("foo") install_gemfile <<-G gem "foo", :git => "#{lib_path("foo")}" G - bundle :install + bundle! :install expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at master@#{revision_for(lib_path("foo"))[0..6]})") expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}" end - it "displays the ref of the gem repository when using branch~num as a ref" do + it "displays the ref of the gem repository when using branch~num as a ref", :bundler => "< 2" do build_git "foo", "1.0", :path => lib_path("foo") rev = revision_for(lib_path("foo"))[0..6] update_git "foo", "2.0", :path => lib_path("foo"), :gemspec => true @@ -32,13 +31,13 @@ RSpec.describe "bundle install" do update_git "foo", "4.0", :path => lib_path("foo"), :gemspec => true - bundle! :update + bundle! :update, :all => bundle_update_requires_all? expect(out).to include("Using foo 2.0 (was 1.0) from #{lib_path("foo")} (at master~2@#{rev2})") expect(the_bundle).to include_gems "foo 2.0", :source => "git@#{lib_path("foo")}" end - it "should check out git repos that are missing but not being installed" do - build_git "foo" + it "should allows git repos that are missing but not being installed" do + revision = build_git("foo").ref_for("HEAD") gemfile <<-G gem "foo", :git => "file://#{lib_path("foo-1.0")}", :group => :development @@ -47,6 +46,7 @@ RSpec.describe "bundle install" do lockfile <<-L GIT remote: file://#{lib_path("foo-1.0")} + revision: #{revision} specs: foo (1.0) @@ -57,10 +57,9 @@ RSpec.describe "bundle install" do foo! L - bundle "install --path=vendor/bundle --without development" + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle", :without => "development") expect(out).to include("Bundle complete!") - expect(vendored_gems("bundler/gems/foo-1.0-#{revision_for(lib_path("foo-1.0"))[0..11]}")).to be_directory end end end diff --git a/spec/bundler/install/global_cache_spec.rb b/spec/bundler/install/global_cache_spec.rb new file mode 100644 index 0000000000..7696dc788f --- /dev/null +++ b/spec/bundler/install/global_cache_spec.rb @@ -0,0 +1,235 @@ +# frozen_string_literal: true + +RSpec.describe "global gem caching" do + before { bundle! "config global_gem_cache true" } + + describe "using the cross-application user cache" do + let(:source) { "http://localgemserver.test" } + let(:source2) { "http://gemserver.example.org" } + + def source_global_cache(*segments) + home(".bundle", "cache", "gems", "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", *segments) + end + + def source2_global_cache(*segments) + home(".bundle", "cache", "gems", "gemserver.example.org.80.1ae1663619ffe0a3c9d97712f44c705b", *segments) + end + + it "caches gems into the global cache on download" do + install_gemfile! <<-G, :artifice => "compact_index" + source "#{source}" + gem "rack" + G + + expect(the_bundle).to include_gems "rack 1.0.0" + expect(source_global_cache("rack-1.0.0.gem")).to exist + end + + it "uses globally cached gems if they exist" do + source_global_cache.mkpath + FileUtils.cp(gem_repo1("gems/rack-1.0.0.gem"), source_global_cache("rack-1.0.0.gem")) + + install_gemfile! <<-G, :artifice => "compact_index_no_gem" + source "#{source}" + gem "rack" + G + + expect(the_bundle).to include_gems "rack 1.0.0" + end + + describe "when the same gem from different sources is installed" do + it "should use the appropriate one from the global cache" do + install_gemfile! <<-G, :artifice => "compact_index" + source "#{source}" + gem "rack" + G + + FileUtils.rm_r(default_bundle_path) + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(source_global_cache("rack-1.0.0.gem")).to exist + # rack 1.0.0 is not installed and it is in the global cache + + install_gemfile! <<-G, :artifice => "compact_index" + source "#{source2}" + gem "rack", "0.9.1" + G + + FileUtils.rm_r(default_bundle_path) + expect(the_bundle).not_to include_gems "rack 0.9.1" + expect(source2_global_cache("rack-0.9.1.gem")).to exist + # rack 0.9.1 is not installed and it is in the global cache + + gemfile <<-G + source "#{source}" + gem "rack", "1.0.0" + G + + bundle! :install, :artifice => "compact_index_no_gem" + # rack 1.0.0 is installed and rack 0.9.1 is not + expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).not_to include_gems "rack 0.9.1" + FileUtils.rm_r(default_bundle_path) + + gemfile <<-G + source "#{source2}" + gem "rack", "0.9.1" + G + + bundle! :install, :artifice => "compact_index_no_gem" + # rack 0.9.1 is installed and rack 1.0.0 is not + expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).not_to include_gems "rack 1.0.0" + end + + it "should not install if the wrong source is provided" do + gemfile <<-G + source "#{source}" + gem "rack" + G + + bundle! :install, :artifice => "compact_index" + FileUtils.rm_r(default_bundle_path) + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(source_global_cache("rack-1.0.0.gem")).to exist + # rack 1.0.0 is not installed and it is in the global cache + + gemfile <<-G + source "#{source2}" + gem "rack", "0.9.1" + G + + bundle! :install, :artifice => "compact_index" + FileUtils.rm_r(default_bundle_path) + expect(the_bundle).not_to include_gems "rack 0.9.1" + expect(source2_global_cache("rack-0.9.1.gem")).to exist + # rack 0.9.1 is not installed and it is in the global cache + + gemfile <<-G + source "#{source2}" + gem "rack", "1.0.0" + G + + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source2_global_cache("rack-0.9.1.gem")).to exist + bundle :install, :artifice => "compact_index_no_gem" + expect(out).to include("Internal Server Error 500") + # rack 1.0.0 is not installed and rack 0.9.1 is not + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(the_bundle).not_to include_gems "rack 0.9.1" + + gemfile <<-G + source "#{source}" + gem "rack", "0.9.1" + G + + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source2_global_cache("rack-0.9.1.gem")).to exist + bundle :install, :artifice => "compact_index_no_gem" + expect(out).to include("Internal Server Error 500") + # rack 0.9.1 is not installed and rack 1.0.0 is not + expect(the_bundle).not_to include_gems "rack 0.9.1" + expect(the_bundle).not_to include_gems "rack 1.0.0" + end + end + + describe "when installing gems from a different directory" do + it "uses the global cache as a source" do + install_gemfile! <<-G, :artifice => "compact_index" + source "#{source}" + gem "rack" + gem "activesupport" + G + + # Both gems are installed and in the global cache + expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "activesupport 2.3.5" + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + FileUtils.rm_r(default_bundle_path) + # Both gems are now only in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(the_bundle).not_to include_gems "activesupport 2.3.5" + + install_gemfile! <<-G, :artifice => "compact_index_no_gem" + source "#{source}" + gem "rack" + G + + # rack is installed and both are in the global cache + expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).not_to include_gems "activesupport 2.3.5" + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + + Dir.chdir bundled_app2 do + create_file bundled_app2("gems.rb"), <<-G + source "#{source}" + gem "activesupport" + G + + # Neither gem is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(the_bundle).not_to include_gems "activesupport 2.3.5" + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + + # Install using the global cache instead of by downloading the .gem + # from the server + bundle! :install, :artifice => "compact_index_no_gem" + + # activesupport is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "activesupport 2.3.5" + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + end + end + end + end + + describe "extension caching", :rubygems => "2.2", :ruby_repo do + it "works" do + build_git "very_simple_git_binary", &:add_c_extension + build_lib "very_simple_path_binary", &:add_c_extension + revision = revision_for(lib_path("very_simple_git_binary-1.0"))[0, 12] + + install_gemfile! <<-G + source "file:#{gem_repo1}" + + gem "very_simple_binary" + gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}" + gem "very_simple_path_binary", :path => "#{lib_path("very_simple_path_binary-1.0")}" + G + + gem_binary_cache = home(".bundle", "cache", "extensions", specific_local_platform.to_s, Bundler.ruby_scope, + Digest(:MD5).hexdigest("#{gem_repo1}/"), "very_simple_binary-1.0") + git_binary_cache = home(".bundle", "cache", "extensions", specific_local_platform.to_s, Bundler.ruby_scope, + "very_simple_git_binary-1.0-#{revision}", "very_simple_git_binary-1.0") + + cached_extensions = Pathname.glob(home(".bundle", "cache", "extensions", "*", "*", "*", "*", "*")).sort + expect(cached_extensions).to eq [gem_binary_cache, git_binary_cache].sort + + run! <<-R + require 'very_simple_binary_c'; puts ::VERY_SIMPLE_BINARY_IN_C + require 'very_simple_git_binary_c'; puts ::VERY_SIMPLE_GIT_BINARY_IN_C + R + expect(out).to eq "VERY_SIMPLE_BINARY_IN_C\nVERY_SIMPLE_GIT_BINARY_IN_C" + + FileUtils.rm Dir[home(".bundle", "cache", "extensions", "**", "*binary_c*")] + + gem_binary_cache.join("very_simple_binary_c.rb").open("w") {|f| f << "puts File.basename(__FILE__)" } + git_binary_cache.join("very_simple_git_binary_c.rb").open("w") {|f| f << "puts File.basename(__FILE__)" } + + bundle! "config --local path different_path" + bundle! :install + + expect(Dir[home(".bundle", "cache", "extensions", "**", "*binary_c*")]).to all(end_with(".rb")) + + run! <<-R + require 'very_simple_binary_c' + require 'very_simple_git_binary_c' + R + expect(out).to eq "very_simple_binary_c.rb\nvery_simple_git_binary_c.rb" + end + end +end diff --git a/spec/bundler/install/path_spec.rb b/spec/bundler/install/path_spec.rb index 7a501d42b3..fc39068f6a 100644 --- a/spec/bundler/install/path_spec.rb +++ b/spec/bundler/install/path_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do describe "with --path" do @@ -14,8 +13,8 @@ RSpec.describe "bundle install" do G end - it "does not use available system gems with bundle --path vendor/bundle" do - bundle "install --path vendor/bundle" + it "does not use available system gems with bundle --path vendor/bundle", :bundler => "< 2" do + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") expect(the_bundle).to include_gems "rack 1.0.0" end @@ -24,25 +23,25 @@ RSpec.describe "bundle install" do dir.mkpath Dir.chdir(dir) do - bundle "install --path vendor/bundle" - expect(out).to include("installed into ./vendor/bundle") + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") + expect(out).to include("installed into `./vendor/bundle`") end dir.rmtree end it "prints a warning to let the user know what has happened with bundle --path vendor/bundle" do - bundle "install --path vendor/bundle" - expect(out).to include("gems are installed into ./vendor") + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") + expect(out).to include("gems are installed into `./vendor/bundle`") end - it "disallows --path vendor/bundle --system" do + it "disallows --path vendor/bundle --system", :bundler => "< 2" do bundle "install --path vendor/bundle --system" expect(out).to include("Please choose only one option.") expect(exitstatus).to eq(15) if exitstatus end - it "remembers to disable system gems after the first time with bundle --path vendor/bundle" do + it "remembers to disable system gems after the first time with bundle --path vendor/bundle", :bundler => "< 2" do bundle "install --path vendor/bundle" FileUtils.rm_rf bundled_app("vendor") bundle "install" @@ -75,7 +74,7 @@ RSpec.describe "bundle install" do [:env, :global].each do |type| it "installs gems to a path if one is specified" do set_bundle_path(type, bundled_app("vendor2").to_s) - bundle "install --path vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") expect(vendored_gems("gems/rack-1.0.0")).to be_directory expect(bundled_app("vendor2")).not_to be_directory @@ -114,7 +113,7 @@ RSpec.describe "bundle install" do end it "sets BUNDLE_PATH as the first argument to bundle install" do - bundle "install --path ./vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "./vendor/bundle") expect(vendored_gems("gems/rack-1.0.0")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" @@ -123,7 +122,7 @@ RSpec.describe "bundle install" do it "disables system gems when passing a path to install" do # This is so that vendored gems can be distributed to others build_gem "rack", "1.1.0", :to_system => true - bundle "install --path ./vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "./vendor/bundle") expect(vendored_gems("gems/rack-1.0.0")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" @@ -139,7 +138,7 @@ RSpec.describe "bundle install" do gem "very_simple_binary" G - bundle "install --path ./vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "./vendor/bundle") expect(vendored_gems("gems/very_simple_binary-1.0")).to be_directory expect(vendored_gems("extensions")).to be_directory @@ -150,7 +149,7 @@ RSpec.describe "bundle install" do run "require 'very_simple_binary_c'" expect(err).to include("Bundler::GemNotFound") - bundle "install --path ./vendor/bundle" + bundle :install, forgotten_command_line_options(:path => "./vendor/bundle") expect(vendored_gems("gems/very_simple_binary-1.0")).to be_directory expect(vendored_gems("extensions")).to be_directory @@ -171,7 +170,7 @@ RSpec.describe "bundle install" do gem "rack" G - bundle "install --path bundle" + bundle :install, forgotten_command_line_options(:path => "bundle") expect(out).to match(/file already exists/) end end diff --git a/spec/bundler/install/post_bundle_message_spec.rb b/spec/bundler/install/post_bundle_message_spec.rb index 4453e4190f..a953847bac 100644 --- a/spec/bundler/install/post_bundle_message_spec.rb +++ b/spec/bundler/install/post_bundle_message_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "post bundle message" do before :each do @@ -14,11 +13,13 @@ RSpec.describe "post bundle message" do G end - let(:bundle_show_message) { "Use `bundle info [gemname]` to see where a bundled gem is installed." } - let(:bundle_deployment_message) { "Bundled gems are installed into ./vendor" } - let(:bundle_complete_message) { "Bundle complete!" } - let(:bundle_updated_message) { "Bundle updated!" } - let(:installed_gems_stats) { "4 Gemfile dependencies, 5 gems now installed." } + let(:bundle_path) { "./.bundle" } + let(:bundle_show_system_message) { "Use `bundle info [gemname]` to see where a bundled gem is installed." } + let(:bundle_show_path_message) { "Bundled gems are installed into `#{bundle_path}`" } + let(:bundle_complete_message) { "Bundle complete!" } + let(:bundle_updated_message) { "Bundle updated!" } + let(:installed_gems_stats) { "4 Gemfile dependencies, 5 gems now installed." } + let(:bundle_show_message) { Bundler::VERSION.split(".").first.to_i < 2 ? bundle_show_system_message : bundle_show_path_message } describe "for fresh bundle install" do it "without any options" do @@ -30,7 +31,7 @@ RSpec.describe "post bundle message" do end it "with --without one group" do - bundle "install --without emo" + bundle! :install, forgotten_command_line_options(:without => "emo") expect(out).to include(bundle_show_message) expect(out).to include("Gems in the group emo were not installed") expect(out).to include(bundle_complete_message) @@ -38,7 +39,7 @@ RSpec.describe "post bundle message" do end it "with --without two groups" do - bundle "install --without emo test" + bundle! :install, forgotten_command_line_options(:without => "emo test") expect(out).to include(bundle_show_message) expect(out).to include("Gems in the groups emo and test were not installed") expect(out).to include(bundle_complete_message) @@ -46,7 +47,7 @@ RSpec.describe "post bundle message" do end it "with --without more groups" do - bundle "install --without emo obama test" + bundle! :install, forgotten_command_line_options(:without => "emo obama test") expect(out).to include(bundle_show_message) expect(out).to include("Gems in the groups emo, obama and test were not installed") expect(out).to include(bundle_complete_message) @@ -54,51 +55,53 @@ RSpec.describe "post bundle message" do end describe "with --path and" do + let(:bundle_path) { "./vendor" } + it "without any options" do - bundle "install --path vendor" - expect(out).to include(bundle_deployment_message) + bundle! :install, forgotten_command_line_options(:path => "vendor") + expect(out).to include(bundle_show_path_message) expect(out).to_not include("Gems in the group") expect(out).to include(bundle_complete_message) end it "with --without one group" do - bundle "install --without emo --path vendor" - expect(out).to include(bundle_deployment_message) + bundle! :install, forgotten_command_line_options(:without => "emo", :path => "vendor") + expect(out).to include(bundle_show_path_message) expect(out).to include("Gems in the group emo were not installed") expect(out).to include(bundle_complete_message) end it "with --without two groups" do - bundle "install --without emo test --path vendor" - expect(out).to include(bundle_deployment_message) + bundle! :install, forgotten_command_line_options(:without => "emo test", :path => "vendor") + expect(out).to include(bundle_show_path_message) expect(out).to include("Gems in the groups emo and test were not installed") expect(out).to include(bundle_complete_message) end it "with --without more groups" do - bundle "install --without emo obama test --path vendor" - expect(out).to include(bundle_deployment_message) + bundle! :install, forgotten_command_line_options(:without => "emo obama test", :path => "vendor") + expect(out).to include(bundle_show_path_message) expect(out).to include("Gems in the groups emo, obama and test were not installed") expect(out).to include(bundle_complete_message) end it "with an absolute --path inside the cwd" do - bundle "install --path #{bundled_app}/cache" - expect(out).to include("Bundled gems are installed into ./cache") + bundle! :install, forgotten_command_line_options(:path => bundled_app("cache")) + expect(out).to include("Bundled gems are installed into `./cache`") expect(out).to_not include("Gems in the group") expect(out).to include(bundle_complete_message) end it "with an absolute --path outside the cwd" do - bundle "install --path #{bundled_app}_cache" - expect(out).to include("Bundled gems are installed into #{bundled_app}_cache") + bundle! :install, forgotten_command_line_options(:path => tmp("not_bundled_app")) + expect(out).to include("Bundled gems are installed into `#{tmp("not_bundled_app")}`") expect(out).to_not include("Gems in the group") expect(out).to include(bundle_complete_message) end end describe "with misspelled or non-existent gem name" do - it "should report a helpful error message" do + it "should report a helpful error message", :bundler => "< 2" do install_gemfile <<-G source "file://#{gem_repo1}" gem "rack" @@ -107,6 +110,18 @@ RSpec.describe "post bundle message" do expect(out).to include("Could not find gem 'not-a-gem' in any of the gem sources listed in your Gemfile.") end + it "should report a helpful error message", :bundler => "2" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "not-a-gem", :group => :development + G + expect(out).to include <<-EOS.strip +Could not find gem 'not-a-gem' in rubygems repository file:#{gem_repo1}/ or installed locally. +The source does not contain any versions of 'not-a-gem' + EOS + end + it "should report a helpful error message with reference to cache if available" do install_gemfile <<-G source "file://#{gem_repo1}" @@ -119,7 +134,8 @@ RSpec.describe "post bundle message" do gem "rack" gem "not-a-gem", :group => :development G - expect(out).to include("Could not find gem 'not-a-gem' in any of the gem sources listed in your Gemfile or in gems cached in vendor/cache.") + expect(out).to include("Could not find gem 'not-a-gem' in"). + and include("or in gems cached in vendor/cache.") end end end @@ -134,8 +150,8 @@ RSpec.describe "post bundle message" do end it "with --without one group" do - bundle "install --without emo" - bundle :install + bundle! :install, forgotten_command_line_options(:without => "emo") + bundle! :install expect(out).to include(bundle_show_message) expect(out).to include("Gems in the group emo were not installed") expect(out).to include(bundle_complete_message) @@ -143,15 +159,15 @@ RSpec.describe "post bundle message" do end it "with --without two groups" do - bundle "install --without emo test" - bundle :install + bundle! :install, forgotten_command_line_options(:without => "emo test") + bundle! :install expect(out).to include(bundle_show_message) expect(out).to include("Gems in the groups emo and test were not installed") expect(out).to include(bundle_complete_message) end it "with --without more groups" do - bundle "install --without emo obama test" + bundle! :install, forgotten_command_line_options(:without => "emo obama test") bundle :install expect(out).to include(bundle_show_message) expect(out).to include("Gems in the groups emo, obama and test were not installed") @@ -161,28 +177,28 @@ RSpec.describe "post bundle message" do describe "for bundle update" do it "without any options" do - bundle :update + bundle! :update, :all => bundle_update_requires_all? expect(out).not_to include("Gems in the groups") expect(out).to include(bundle_updated_message) end it "with --without one group" do - bundle :install, :without => :emo - bundle :update + bundle! :install, forgotten_command_line_options(:without => "emo") + bundle! :update, :all => bundle_update_requires_all? expect(out).to include("Gems in the group emo were not installed") expect(out).to include(bundle_updated_message) end it "with --without two groups" do - bundle "install --without emo test" - bundle :update + bundle! :install, forgotten_command_line_options(:without => "emo test") + bundle! :update, :all => bundle_update_requires_all? expect(out).to include("Gems in the groups emo and test were not installed") expect(out).to include(bundle_updated_message) end it "with --without more groups" do - bundle "install --without emo obama test" - bundle :update + bundle! :install, forgotten_command_line_options(:without => "emo obama test") + bundle! :update, :all => bundle_update_requires_all? expect(out).to include("Gems in the groups emo, obama and test were not installed") expect(out).to include(bundle_updated_message) end diff --git a/spec/bundler/install/prereleases_spec.rb b/spec/bundler/install/prereleases_spec.rb index 6c32094d90..7af8c3b304 100644 --- a/spec/bundler/install/prereleases_spec.rb +++ b/spec/bundler/install/prereleases_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundle install" do describe "when prerelease gems are available" do diff --git a/spec/bundler/install/process_lock_spec.rb b/spec/bundler/install/process_lock_spec.rb new file mode 100644 index 0000000000..02217f493b --- /dev/null +++ b/spec/bundler/install/process_lock_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +RSpec.describe "process lock spec" do + describe "when an install operation is already holding a process lock" do + before { FileUtils.mkdir_p(default_bundle_path) } + + it "will not run a second concurrent bundle install until the lock is released" do + thread = Thread.new do + Bundler::ProcessLock.lock(default_bundle_path) do + sleep 1 # ignore quality_spec + expect(the_bundle).not_to include_gems "rack 1.0" + end + end + + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + thread.join + expect(the_bundle).to include_gems "rack 1.0" + end + end +end diff --git a/spec/bundler/install/security_policy_spec.rb b/spec/bundler/install/security_policy_spec.rb index ab531bdad6..7be09d6bd4 100644 --- a/spec/bundler/install/security_policy_spec.rb +++ b/spec/bundler/install/security_policy_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require "spec_helper" + require "rubygems/security" # unfortunately, testing signed gems with a provided CA is extremely difficult @@ -24,7 +24,7 @@ RSpec.describe "policies with unsigned gems" do it "will fail when given invalid security policy" do bundle "install --trust-policy=InvalidPolicyName" - expect(out).to include("Rubygems doesn't know about trust policy") + expect(out).to include("RubyGems doesn't know about trust policy") end it "will fail with High Security setting due to presence of unsigned gem" do @@ -32,7 +32,7 @@ RSpec.describe "policies with unsigned gems" do expect(out).to include("security policy didn't allow") end - # This spec will fail on Rubygems 2 rc1 due to a bug in policy.rb. the bug is fixed in rc3. + # This spec will fail on RubyGems 2 rc1 due to a bug in policy.rb. the bug is fixed in rc3. it "will fail with Medium Security setting due to presence of unsigned gem", :unless => ENV["RGV"] == "v2.0.0.rc.1" do bundle "install --trust-policy=MediumSecurity" expect(out).to include("security policy didn't allow") diff --git a/spec/bundler/install/yanked_spec.rb b/spec/bundler/install/yanked_spec.rb index d42978ce4c..7c4b98bfdf 100644 --- a/spec/bundler/install/yanked_spec.rb +++ b/spec/bundler/install/yanked_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.context "when installing a bundle that includes yanked gems" do before(:each) do @@ -38,7 +37,7 @@ RSpec.context "when installing a bundle that includes yanked gems" do G expect(out).not_to include("Your bundle is locked to foo (10.0.0)") - expect(out).to include("Could not find gem 'foo (= 10.0.0)' in any of the gem sources") + expect(out).to include("Could not find gem 'foo (= 10.0.0)' in") end end |