diff options
Diffstat (limited to 'spec/commands')
-rw-r--r-- | spec/commands/add_spec.rb | 26 | ||||
-rw-r--r-- | spec/commands/binstubs_spec.rb | 22 | ||||
-rw-r--r-- | spec/commands/check_spec.rb | 10 | ||||
-rw-r--r-- | spec/commands/clean_spec.rb | 71 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 42 | ||||
-rw-r--r-- | spec/commands/console_spec.rb | 2 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 175 | ||||
-rw-r--r-- | spec/commands/info_spec.rb | 114 | ||||
-rw-r--r-- | spec/commands/init_spec.rb | 98 | ||||
-rw-r--r-- | spec/commands/inject_spec.rb | 14 | ||||
-rw-r--r-- | spec/commands/install_spec.rb | 12 | ||||
-rw-r--r-- | spec/commands/list_spec.rb | 75 | ||||
-rw-r--r-- | spec/commands/lock_spec.rb | 2 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 14 | ||||
-rw-r--r-- | spec/commands/outdated_spec.rb | 6 | ||||
-rw-r--r-- | spec/commands/package_spec.rb | 18 | ||||
-rw-r--r-- | spec/commands/pristine_spec.rb | 9 | ||||
-rw-r--r-- | spec/commands/show_spec.rb | 27 | ||||
-rw-r--r-- | spec/commands/update_spec.rb | 115 | ||||
-rw-r--r-- | spec/commands/version_spec.rb | 12 |
20 files changed, 594 insertions, 270 deletions
diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb index dac1d0f6b9..f5b3f49bb1 100644 --- a/spec/commands/add_spec.rb +++ b/spec/commands/add_spec.rb @@ -11,6 +11,8 @@ RSpec.describe "bundle add" do build_gem "dog", "1.1.3.pre" end + build_git "foo", "2.0" + install_gemfile <<-G source "file://#{gem_repo2}" gem "weakling", "~> 0.0.1" @@ -21,7 +23,7 @@ RSpec.describe "bundle add" do it "shows error" do bundle "add" - expect(last_command.bundler_err).to include("Please specify gems to add") + expect(err).to include("Please specify gems to add") end end @@ -89,6 +91,28 @@ RSpec.describe "bundle add" do end end + describe "with --git" do + it "adds dependency with specified github source" do + bundle "add foo --git=#{lib_path("foo-2.0")}" + + expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/) + expect(the_bundle).to include_gems "foo 2.0" + end + end + + describe "with --git and --branch" do + before do + update_git "foo", "2.0", :branch => "test" + end + + it "adds dependency with specified github source and branch" do + bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test" + + expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/) + expect(the_bundle).to include_gems "foo 2.0" + end + end + describe "with --skip-install" do it "adds gem to Gemfile but is not installed" do bundle "add foo --skip-install --version=2.0" diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index 9126b29592..4f310784c7 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -70,7 +70,7 @@ RSpec.describe "bundle binstubs <gem>" do bundle "binstubs rack", :all => true expect(last_command).to be_failure - expect(last_command.bundler_err).to include("Cannot specify --all with specific gems") + expect(err).to include("Cannot specify --all with specific gems") end context "when generating bundle binstub outside bundler" do @@ -88,7 +88,7 @@ RSpec.describe "bundle binstubs <gem>" do sys_exec "bin/rackup" - expect(last_command.stderr).to include("was not generated by Bundler") + expect(err).to include("was not generated by Bundler") end end @@ -135,7 +135,7 @@ RSpec.describe "bundle binstubs <gem>" do it "runs the correct version of bundler" do sys_exec "#{bundled_app("bin/bundle")} install", "BUNDLER_VERSION" => "999.999.999" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (999.999.999) failed:"). + expect(err).to include("Activating bundler (999.999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") end end @@ -145,7 +145,7 @@ RSpec.describe "bundle binstubs <gem>" do lockfile lockfile.gsub(system_bundler_version, "999.999.999") sys_exec "#{bundled_app("bin/bundle")} install" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (999.999.999) failed:"). + expect(err).to include("Activating bundler (999.999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") end @@ -154,7 +154,7 @@ RSpec.describe "bundle binstubs <gem>" do lockfile lockfile.gsub(system_bundler_version, "44.0") sys_exec "#{bundled_app("bin/bundle")} install" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (44.0) failed:"). + expect(err).to include("Activating bundler (44.0) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '44.0'`") end @@ -163,7 +163,7 @@ RSpec.describe "bundle binstubs <gem>" do lockfile lockfile.gsub(system_bundler_version, "2.12.0.a") sys_exec "#{bundled_app("bin/bundle")} install" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (2.12.0.a) failed:"). + expect(err).to include("Activating bundler (2.12.0.a) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '2.12.0.a'`") end end @@ -173,13 +173,13 @@ RSpec.describe "bundle binstubs <gem>" do it "calls through to the latest bundler version" do sys_exec! "#{bundled_app("bin/bundle")} update --bundler" - expect(last_command.stdout).to eq %(system bundler #{system_bundler_version}\n["update", "--bundler"]) + expect(out).to eq %(system bundler #{system_bundler_version}\n["update", "--bundler"]) end it "calls through to the explicit bundler version" do sys_exec "#{bundled_app("bin/bundle")} update --bundler=999.999.999" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (999.999.999) failed:"). + expect(err).to include("Activating bundler (999.999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") end end @@ -202,10 +202,10 @@ RSpec.describe "bundle binstubs <gem>" do context "when requesting a different bundler version" do before { lockfile lockfile.gsub(Bundler::VERSION, "999.999.999") } - it "attempts to load that version", :ruby_repo do + it "attempts to load that version" do sys_exec bundled_app("bin/rackup").to_s expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (999.999.999) failed:"). + expect(err).to include("Activating bundler (999.999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") end end @@ -294,7 +294,7 @@ RSpec.describe "bundle binstubs <gem>" do expect(bundled_app("exec/rackup")).to exist end - it "setting is saved for bundle install", :bundler => "< 2" do + it "setting is saved for bundle install", :bundler => "< 3" do install_gemfile <<-G source "file://#{gem_repo1}" gem "rack" diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb index b16cfc37e7..cf88736612 100644 --- a/spec/commands/check_spec.rb +++ b/spec/commands/check_spec.rb @@ -92,7 +92,7 @@ RSpec.describe "bundle check" do expect(err).to include("Bundler can't satisfy your Gemfile's dependencies.") end - it "remembers --without option from install", :bundler => "< 2" do + it "remembers --without option from install", :bundler => "< 3" do gemfile <<-G source "file://#{gem_repo1}" group :foo do @@ -106,7 +106,7 @@ RSpec.describe "bundle check" do end it "uses the without setting" do - bundle! "config without foo" + bundle! "config set without foo" install_gemfile! <<-G source "file://#{gem_repo1}" group :foo do @@ -238,7 +238,7 @@ RSpec.describe "bundle check" do expect(last_command).to be_failure end - context "--path", :bundler => "< 2" do + context "--path", :bundler => "< 3" do before do gemfile <<-G source "file://#{gem_repo1}" @@ -254,7 +254,7 @@ RSpec.describe "bundle check" do expect(out).to include("The Gemfile's dependencies are satisfied") end - it "should write to .bundle/config", :bundler => "< 2" do + it "should write to .bundle/config", :bundler => "< 3" do bundle "check --path vendor/bundle" bundle! "check" end @@ -338,7 +338,7 @@ RSpec.describe "bundle check" do it "does not change the lock but warns" do lockfile lock_with(Bundler::VERSION.succ) bundle! :check - expect(last_command.bundler_err).to include("the running version of Bundler (#{Bundler::VERSION}) is older than the version that created the lockfile (#{Bundler::VERSION.succ})") + expect(err).to include("the running version of Bundler (#{Bundler::VERSION}) is older than the version that created the lockfile (#{Bundler::VERSION.succ})") lockfile_should_be lock_with(Bundler::VERSION.succ) end end diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 6cd796f694..0053947c85 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -142,7 +142,7 @@ RSpec.describe "bundle clean" do bundle :clean digest = Digest(:SHA1).hexdigest(git_path.to_s) - cache_path = Bundler::VERSION.start_with?("1.") ? vendored_gems("cache/bundler/git/foo-1.0-#{digest}") : home(".bundle/cache/git/foo-1.0-#{digest}") + cache_path = Bundler::VERSION.start_with?("2.") ? vendored_gems("cache/bundler/git/foo-1.0-#{digest}") : home(".bundle/cache/git/foo-1.0-#{digest}") expect(cache_path).to exist end @@ -201,7 +201,7 @@ RSpec.describe "bundle clean" do update_git "foo", :path => lib_path("foo-bar") revision2 = revision_for(lib_path("foo-bar")) - bundle! "update", :all => bundle_update_requires_all? + bundle! "update", :all => true bundle! :clean expect(out).to include("Removing foo-bar (#{revision[0..11]})") @@ -276,7 +276,7 @@ RSpec.describe "bundle clean" do end it "displays an error when used without --path" do - bundle! "config path.system true" + bundle! "config set path.system true" install_gemfile <<-G source "file://#{gem_repo1}" @@ -320,9 +320,7 @@ RSpec.describe "bundle clean" do end it "does not call clean automatically when using system gems" do - bundle! "config path.system true" - - bundle! "config list" + bundle! "config set path.system true" install_gemfile! <<-G source "file://#{gem_repo1}" @@ -331,8 +329,6 @@ RSpec.describe "bundle clean" do gem "rack" G - bundle! "info thin" - install_gemfile! <<-G source "file://#{gem_repo1}" @@ -344,7 +340,7 @@ RSpec.describe "bundle clean" do expect(out).to include("rack (1.0.0)").and include("thin (1.0)") end - it "--clean should override the bundle setting on install", :bundler => "< 2" do + it "--clean should override the bundle setting on install", :bundler => "< 3" do gemfile <<-G source "file://#{gem_repo1}" @@ -364,7 +360,7 @@ RSpec.describe "bundle clean" do should_not_have_gems "thin-1.0" end - it "--clean should override the bundle setting on update", :bundler => "< 2" do + it "--clean should override the bundle setting on update", :bundler => "< 3" do build_repo2 gemfile <<-G @@ -378,13 +374,13 @@ RSpec.describe "bundle clean" do build_gem "foo", "1.0.1" end - bundle! "update", :all => bundle_update_requires_all? + bundle! "update", :all => true should_have_gems "foo-1.0.1" should_not_have_gems "foo-1.0" end - it "automatically cleans when path has not been set", :bundler => "2" do + it "automatically cleans when path has not been set", :bundler => "3" do build_repo2 install_gemfile! <<-G @@ -441,12 +437,12 @@ RSpec.describe "bundle clean" do build_gem "foo", "1.0.1" end - bundle! :update, :all => bundle_update_requires_all? + bundle! :update, :all => true should_have_gems "foo-1.0", "foo-1.0.1" end it "does not clean on bundle update when using --system" do - bundle! "config path.system true" + bundle! "config set path.system true" build_repo2 @@ -460,7 +456,7 @@ RSpec.describe "bundle clean" do update_repo2 do build_gem "foo", "1.0.1" end - bundle! :update, :all => bundle_update_requires_all? + bundle! :update, :all => true gem = ruby_core? ? ENV["BUNDLE_GEM"] : "gem" sys_exec! "#{gem} list" @@ -468,7 +464,7 @@ RSpec.describe "bundle clean" do end it "cleans system gems when --force is used" do - bundle! "config path.system true" + bundle! "config set path.system true" gemfile <<-G source "file://#{gem_repo1}" @@ -560,7 +556,7 @@ RSpec.describe "bundle clean" do end it "when using --force on system gems, it doesn't remove binaries" do - bundle! "config path.system true" + bundle! "config set path.system true" build_repo2 update_repo2 do @@ -707,7 +703,7 @@ RSpec.describe "bundle clean" do gem "weakling" G - bundle! "config auto_install 1" + bundle! "config set auto_install 1" bundle! :clean expect(out).to include("Installing weakling 0.0.3") should_have_gems "thin-1.0", "rack-1.0.0", "weakling-0.0.3" @@ -770,4 +766,43 @@ RSpec.describe "bundle clean" do expect(very_simple_binary_extensions_dir).not_to exist expect(simple_binary_extensions_dir).to exist end + + it "removes git extension directories", :ruby_repo do + build_git "very_simple_git_binary", &:add_c_extension + + revision = revision_for(lib_path("very_simple_git_binary-1.0")) + short_revision = revision[0..11] + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" + G + + bundle! "install", forgotten_command_line_options(:path => "vendor/bundle") + + very_simple_binary_extensions_dir = + Pathname.glob("#{vendored_gems}/bundler/gems/extensions/*/*/very_simple_git_binary-1.0-#{short_revision}").first + + expect(very_simple_binary_extensions_dir).to exist + + gemfile <<-G + gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" + G + + bundle! "install" + bundle! :clean + expect(out).to include("Removing thin (1.0)") + expect(very_simple_binary_extensions_dir).to exist + + gemfile <<-G + G + + bundle! "install" + bundle! :clean + expect(out).to eq("Removing very_simple_git_binary-1.0 (#{short_revision})") + + expect(very_simple_binary_extensions_dir).not_to exist + end end diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index 878b75f865..40fab95803 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -389,88 +389,88 @@ E end describe "subcommands" do - it "list" do + it "list", :ruby_repo do bundle! "config list" - expect(last_command.stdout).to eq "Settings are listed in order of priority. The top value will be used.\nspec_run\nSet via BUNDLE_SPEC_RUN: \"true\"" + expect(out).to eq "Settings are listed in order of priority. The top value will be used.\nspec_run\nSet via BUNDLE_SPEC_RUN: \"true\"" bundle! "config list", :parseable => true - expect(last_command.stdout).to eq "spec_run=true" + expect(out).to eq "spec_run=true" end it "get" do ENV["BUNDLE_BAR"] = "bar_val" bundle! "config get foo" - expect(last_command.stdout).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(out).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" ENV["BUNDLE_FOO"] = "foo_val" bundle! "config get foo --parseable" - expect(last_command.stdout).to eq "foo=foo_val" + expect(out).to eq "foo=foo_val" bundle! "config get foo" - expect(last_command.stdout).to eq "Settings for `foo` in order of priority. The top value will be used\nSet via BUNDLE_FOO: \"foo_val\"" + expect(out).to eq "Settings for `foo` in order of priority. The top value will be used\nSet via BUNDLE_FOO: \"foo_val\"" end it "set" do bundle! "config set foo 1" - expect(last_command.stdout).to eq "" + expect(out).to eq "" bundle! "config set --local foo 2" - expect(last_command.stdout).to eq "" + expect(out).to eq "" bundle! "config set --global foo 3" - expect(last_command.stdout).to eq "Your application has set foo to \"2\". This will override the global value you are currently setting" + expect(out).to eq "Your application has set foo to \"2\". This will override the global value you are currently setting" bundle! "config set --parseable --local foo 4" - expect(last_command.stdout).to eq "foo=4" + expect(out).to eq "foo=4" bundle! "config set --local foo 4.1" - expect(last_command.stdout).to eq "You are replacing the current local value of foo, which is currently \"4\"" + expect(out).to eq "You are replacing the current local value of foo, which is currently \"4\"" bundle "config set --global --local foo 5" expect(last_command).to be_failure - expect(last_command.bundler_err).to eq "The options global and local were specified. Please only use one of the switches at a time." + expect(err).to eq "The options global and local were specified. Please only use one of the switches at a time." end it "unset" do bundle! "config unset foo" - expect(last_command.stdout).to eq "" + expect(out).to eq "" bundle! "config set foo 1" bundle! "config unset foo --parseable" - expect(last_command.stdout).to eq "" + expect(out).to eq "" bundle! "config set --local foo 1" bundle! "config set --global foo 2" bundle! "config unset foo" - expect(last_command.stdout).to eq "" + expect(out).to eq "" expect(bundle!("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" bundle! "config set --local foo 1" bundle! "config set --global foo 2" bundle! "config unset foo --local" - expect(last_command.stdout).to eq "" + expect(out).to eq "" expect(bundle!("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nSet for the current user (#{home(".bundle/config")}): \"2\"" bundle! "config unset foo --global" - expect(last_command.stdout).to eq "" + expect(out).to eq "" expect(bundle!("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" bundle! "config set --local foo 1" bundle! "config set --global foo 2" bundle! "config unset foo --global" - expect(last_command.stdout).to eq "" + expect(out).to eq "" expect(bundle!("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nSet for your local app (#{bundled_app(".bundle/config")}): \"1\"" bundle! "config unset foo --local" - expect(last_command.stdout).to eq "" + expect(out).to eq "" expect(bundle!("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" bundle "config unset foo --local --global" expect(last_command).to be_failure - expect(last_command.bundler_err).to eq "The options global and local were specified. Please only use one of the switches at a time." + expect(err).to eq "The options global and local were specified. Please only use one of the switches at a time." end end end @@ -488,7 +488,7 @@ RSpec.describe "setting gemfile via config" do bundle "config set --local gemfile #{bundled_app("NotGemfile")}" expect(File.exist?(".bundle/config")).to eq(true) - bundle "config" + bundle "config list" expect(out).to include("NotGemfile") end end diff --git a/spec/commands/console_spec.rb b/spec/commands/console_spec.rb index 41fc56c919..cba618db80 100644 --- a/spec/commands/console_spec.rb +++ b/spec/commands/console_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "bundle console", :bundler => "< 2" do +RSpec.describe "bundle console", :bundler => "< 3" do before :each do install_gemfile <<-G source "file://#{gem_repo1}" diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index d339486ed1..24aa5f46fe 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -88,14 +88,14 @@ RSpec.describe "bundle exec" do sys_exec "#{Gem.ruby} #{command.path}" expect(out).to eq("") - expect(last_command.stderr).to be_empty + expect(err).to be_empty end it "accepts --keep-file-descriptors" do install_gemfile "" bundle "exec --keep-file-descriptors echo foobar" - expect(last_command.stderr).to be_empty + expect(err).to be_empty end it "can run a command named --verbose" do @@ -140,6 +140,112 @@ RSpec.describe "bundle exec" do end end + context "with default gems" do + let(:system_gems_to_install) { [] } + + let(:default_irb_version) { ruby "gem 'irb', '< 999999'; require 'irb'; puts IRB::VERSION" } + + context "when not specified in Gemfile" do + before do + skip "irb isn't a default gem" if default_irb_version.empty? + + install_gemfile "" + end + + it "uses version provided by ruby" do + bundle! "exec irb --version" + + expect(out).to include(default_irb_version) + expect(err).to be_empty + end + end + + context "when specified in Gemfile directly" do + let(:specified_irb_version) { "0.9.6" } + + before do + skip "irb isn't a default gem" if default_irb_version.empty? + + build_repo2 do + build_gem "irb", specified_irb_version do |s| + s.executables = "irb" + end + end + + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "irb", "#{specified_irb_version}" + G + end + + it "uses version specified" do + bundle! "exec irb --version" + + expect(out).to include(specified_irb_version) + expect(err).to be_empty + end + end + + context "when specified in Gemfile indirectly" do + let(:indirect_irb_version) { "0.9.6" } + + before do + skip "irb isn't a default gem" if default_irb_version.empty? + + build_repo2 do + build_gem "irb", indirect_irb_version do |s| + s.executables = "irb" + end + + build_gem "gem_depending_on_old_irb" do |s| + s.add_dependency "irb", indirect_irb_version + end + end + + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "gem_depending_on_old_irb" + G + + bundle! "exec irb --version" + end + + it "uses resolved version" do + expect(out).to include(indirect_irb_version) + expect(err).to be_empty + end + end + end + + it "warns about executable conflicts" do + build_repo2 do + build_gem "rack_two", "1.0.0" do |s| + s.executables = "rackup" + end + end + + bundle "config set path.system true" + + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "0.9.1" + G + + Dir.chdir bundled_app2 do + install_gemfile bundled_app2("Gemfile"), <<-G + source "file://#{gem_repo2}" + gem "rack_two", "1.0.0" + G + end + + bundle! "exec rackup" + + expect(last_command.stderr).to eq( + "Bundler is using a binstub that was created for a different gem (rack).\n" \ + "You should run `bundle binstub rack_two` to work around a system/bundle conflict." + ) + end + it "handles gems installed with --without" do install_gemfile <<-G, forgotten_command_line_options(:without => "middleware") source "file://#{gem_repo1}" @@ -220,15 +326,15 @@ RSpec.describe "bundle exec" do end it "raises a helpful error when exec'ing to something outside of the bundle", :ruby_repo do - bundle! "config clean false" # want to keep the rackup binstub + bundle! "config set clean false" # want to keep the rackup binstub install_gemfile! <<-G source "file://#{gem_repo1}" gem "with_license" G [true, false].each do |l| - bundle! "config disable_exec_load #{l}" + bundle! "config set disable_exec_load #{l}" bundle "exec rackup" - expect(last_command.stderr).to include "can't find executable rackup for gem rack. rack is not currently included in the bundle, perhaps you meant to add it to your Gemfile?" + expect(err).to include "can't find executable rackup for gem rack. rack is not currently included in the bundle, perhaps you meant to add it to your Gemfile?" end end @@ -424,7 +530,7 @@ RSpec.describe "bundle exec" do expect(out).to include("Installing foo 1.0") end - describe "with gems bundled via :path with invalid gemspecs", :ruby_repo do + describe "with gems bundled via :path with invalid gemspecs" do it "outputs the gemspec validation errors" do build_lib "foo" @@ -446,8 +552,8 @@ RSpec.describe "bundle exec" do bundle "exec irb" - expect(last_command.stderr).to match("The gemspec at #{lib_path("foo-1.0").join("foo.gemspec")} is not valid") - expect(last_command.stderr).to match('"TODO" is not a summary') + expect(err).to match("The gemspec at #{lib_path("foo-1.0").join("foo.gemspec")} is not valid") + expect(err).to match('"TODO" is not a summary') end end @@ -508,8 +614,8 @@ RSpec.describe "bundle exec" do it "like a normally executed executable" do subject expect(exitstatus).to eq(exit_code) if exitstatus - expect(last_command.stderr).to eq(expected_err) - expect(last_command.stdout).to eq(expected) + expect(err).to eq(expected_err) + expect(out).to eq(expected) end end @@ -544,17 +650,7 @@ RSpec.describe "bundle exec" do it_behaves_like "it runs" end - context "the executable is empty", :bundler => "< 2" do - let(:executable) { "" } - - let(:exit_code) { 0 } - let(:expected) { "#{path} is empty" } - let(:expected_err) { "" } - - it_behaves_like "it runs" - end - - context "the executable is empty", :bundler => "2" do + context "the executable is empty" do let(:executable) { "" } let(:exit_code) { 0 } @@ -563,18 +659,7 @@ RSpec.describe "bundle exec" do it_behaves_like "it runs" end - context "the executable raises", :bundler => "< 2" do - let(:executable) { super() << "\nraise 'ERROR'" } - let(:exit_code) { 1 } - let(:expected) { super() << "\nbundler: failed to load command: #{path} (#{path})" } - let(:expected_err) do - "RuntimeError: ERROR\n #{path}:10" + - (Bundler.current_ruby.ruby_18? ? "" : ":in `<top (required)>'") - end - it_behaves_like "it runs" - end - - context "the executable raises", :bundler => "2" do + context "the executable raises" do let(:executable) { super() << "\nraise 'ERROR'" } let(:exit_code) { 1 } let(:expected_err) do @@ -584,16 +669,7 @@ RSpec.describe "bundle exec" do it_behaves_like "it runs" end - context "the executable raises an error without a backtrace", :bundler => "< 2" do - let(:executable) { super() << "\nclass Err < Exception\ndef backtrace; end;\nend\nraise Err" } - let(:exit_code) { 1 } - let(:expected) { super() << "\nbundler: failed to load command: #{path} (#{path})" } - let(:expected_err) { "Err: Err" } - - it_behaves_like "it runs" - end - - context "the executable raises an error without a backtrace", :bundler => "2" do + context "the executable raises an error without a backtrace" do let(:executable) { super() << "\nclass Err < Exception\ndef backtrace; end;\nend\nraise Err" } let(:exit_code) { 1 } let(:expected_err) { "bundler: failed to load command: #{path} (#{path})\nErr: Err" } @@ -607,7 +683,7 @@ RSpec.describe "bundle exec" do it_behaves_like "it runs" end - context "when Bundler.setup fails", :bundler => "< 2" do + context "when Bundler.setup fails", :bundler => "< 3" do before do gemfile <<-G gem 'rack', '2' @@ -616,7 +692,8 @@ RSpec.describe "bundle exec" do end let(:exit_code) { Bundler::GemNotFound.new.status_code } - let(:expected) { <<-EOS.strip } + let(:expected) { "" } + let(:expected_err) { <<-EOS.strip } \e[31mCould not find gem 'rack (= 2)' in any of the gem sources listed in your Gemfile.\e[0m \e[33mRun `bundle install` to install missing gems.\e[0m EOS @@ -624,7 +701,7 @@ RSpec.describe "bundle exec" do it_behaves_like "it runs" end - context "when Bundler.setup fails", :bundler => "2" do + context "when Bundler.setup fails", :bundler => "3" do before do gemfile <<-G gem 'rack', '2' @@ -759,9 +836,7 @@ __FILE__: #{path.to_s.inspect} bundle :install, :system_bundler => true, :path => "vendor/bundler" end - it "overrides disable_shared_gems so bundler can be found", :rubygems => ">= 2.6.2" do - skip "bundler 1.16.x is not support with Ruby 2.6 on Travis CI" if RUBY_VERSION >= "2.6" - + it "overrides disable_shared_gems so bundler can be found", :ruby_repo, :rubygems => ">= 2.6.2" do system_gems :bundler file = bundled_app("file_that_bundle_execs.rb") create_file(file, <<-RB) @@ -811,7 +886,7 @@ __FILE__: #{path.to_s.inspect} # sanity check that we get the newer, custom version without bundler sys_exec("#{Gem.ruby} #{file}") - expect(last_command.stderr).to include("custom openssl should not be loaded") + expect(err).to include("custom openssl should not be loaded") end end end diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index 20fe0038a6..f0f4b5f87d 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe "bundle info" do - context "info from specific gem in gemfile" do + context "with a standard Gemfile" do before do install_gemfile <<-G source "file://#{gem_repo1}" @@ -9,19 +9,35 @@ RSpec.describe "bundle info" do G end - it "prints information about the current gem" do + it "creates a Gemfile.lock when invoked with a gem name" do + FileUtils.rm("Gemfile.lock") + + bundle "info rails" + + expect(bundled_app("Gemfile.lock")).to exist + end + + it "prints information if gem exists in bundle" do bundle "info rails" expect(out).to include "* rails (2.3.2) \tSummary: This is just a fake gem for testing -\tHomepage: http://example.com" - expect(out).to match(%r{Path\: .*\/rails\-2\.3\.2}) +\tHomepage: http://example.com +\tPath: #{default_bundle_path("gems", "rails-2.3.2")}" end - context "given a gem that is not installed" do - it "prints missing gem error" do - bundle "info foo" - expect(err).to eq "Could not find gem 'foo'." - end + it "prints path if gem exists in bundle" do + bundle "info rails --path" + expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) + end + + it "prints the path to the running bundler" do + bundle "info bundler --path" + expect(out).to eq(root.to_s) + end + + it "complains if gem not in bundle" do + bundle "info missing" + expect(err).to eq("Could not find gem 'missing'.") end context "given a default gem shippped in ruby", :ruby_repo do @@ -46,12 +62,84 @@ RSpec.describe "bundle info" do expect(out).to_not include("Homepage:") end end + end + + context "with a git repo in the Gemfile" do + before :each do + @git = build_git "foo", "1.0" + end + + it "prints out git info" do + install_gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}" + G + expect(the_bundle).to include_gems "foo 1.0" + + bundle "info foo" + expect(out).to include("foo (1.0 #{@git.ref_for("master", 6)}") + end - context "given --path option" do - it "prints the path to the gem" do - bundle "info rails" - expect(out).to match(%r{.*\/rails\-2\.3\.2}) + it "prints out branch names other than master" do + update_git "foo", :branch => "omg" do |s| + s.write "lib/foo.rb", "FOO = '1.0.omg'" end + @revision = revision_for(lib_path("foo-1.0"))[0...6] + + install_gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "omg" + G + expect(the_bundle).to include_gems "foo 1.0.omg" + + bundle "info foo" + expect(out).to include("foo (1.0 #{@git.ref_for("omg", 6)}") + end + + it "doesn't print the branch when tied to a ref" do + sha = revision_for(lib_path("foo-1.0")) + install_gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{sha}" + G + + bundle "info foo" + expect(out).to include("foo (1.0 #{sha[0..6]})") + end + + it "handles when a version is a '-' prerelease", :rubygems => "2.1" do + @git = build_git("foo", "1.0.0-beta.1", :path => lib_path("foo")) + install_gemfile <<-G + gem "foo", "1.0.0-beta.1", :git => "#{lib_path("foo")}" + G + expect(the_bundle).to include_gems "foo 1.0.0.pre.beta.1" + + bundle! "info foo" + expect(out).to include("foo (1.0.0.pre.beta.1") + end + end + + context "with a valid regexp for gem name", :ruby_repo do + it "presents alternatives" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rack-obama" + G + + bundle "info rac" + expect(out).to eq "1 : rack\n2 : rack-obama\n0 : - exit -\n>" + end + end + + context "with an invalid regexp for gem name" do + it "does not find the gem" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + invalid_regexp = "[]" + + bundle "info #{invalid_regexp}" + expect(err).to include("Could not find gem '#{invalid_regexp}'.") end end end diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb index 3685cd9c36..7960ce85bd 100644 --- a/spec/commands/init_spec.rb +++ b/spec/commands/init_spec.rb @@ -1,19 +1,13 @@ # frozen_string_literal: true RSpec.describe "bundle init" do - it "generates a Gemfile", :bundler => "< 2" do + it "generates a Gemfile" do bundle! :init expect(out).to include("Writing new Gemfile") expect(bundled_app("Gemfile")).to be_file end - it "generates a gems.rb", :bundler => "2" do - bundle! :init - expect(out).to include("Writing new gems.rb") - expect(bundled_app("gems.rb")).to be_file - end - - context "when a Gemfile already exists", :bundler => "< 2" do + context "when a Gemfile already exists" do before do create_file "Gemfile", <<-G gem "rails" @@ -30,24 +24,7 @@ RSpec.describe "bundle init" do end end - context "when gems.rb already exists", :bundler => ">= 2" do - before do - create_file("gems.rb", <<-G) - gem "rails" - G - end - - it "does not change existing Gemfiles" do - expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) } - end - - it "notifies the user that an existing gems.rb already exists" do - bundle :init - expect(err).to include("gems.rb already exists") - end - end - - context "when a Gemfile exists in a parent directory", :bundler => "< 2" do + context "when a Gemfile exists in a parent directory" do let(:subdir) { "child_dir" } it "lets users generate a Gemfile in a child directory" do @@ -82,24 +59,7 @@ RSpec.describe "bundle init" do end end - context "when a gems.rb file exists in a parent directory", :bundler => ">= 2" do - let(:subdir) { "child_dir" } - - it "lets users generate a Gemfile in a child directory" do - bundle! :init - - FileUtils.mkdir bundled_app(subdir) - - Dir.chdir bundled_app(subdir) do - bundle! :init - end - - expect(out).to include("Writing new gems.rb") - expect(bundled_app("#{subdir}/gems.rb")).to be_file - end - end - - context "given --gemspec option", :bundler => "< 2" do + context "given --gemspec option" do let(:spec_file) { tmp.join("test.gemspec") } it "should generate from an existing gemspec" do @@ -115,11 +75,7 @@ RSpec.describe "bundle init" do bundle :init, :gemspec => spec_file - gemfile = if Bundler::VERSION[0, 2] == "1." - bundled_app("Gemfile").read - else - bundled_app("gems.rb").read - end + gemfile = bundled_app("Gemfile").read expect(gemfile).to match(%r{source 'https://rubygems.org'}) expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) @@ -138,7 +94,7 @@ RSpec.describe "bundle init" do end bundle :init, :gemspec => spec_file - expect(last_command.bundler_err).to include("There was an error while loading `test.gemspec`") + expect(err).to include("There was an error while loading `test.gemspec`") end end end @@ -146,7 +102,47 @@ RSpec.describe "bundle init" do context "when init_gems_rb setting is enabled" do before { bundle "config set init_gems_rb true" } - context "given --gemspec option", :bundler => "< 2" do + it "generates a gems.rb" do + bundle! :init + expect(out).to include("Writing new gems.rb") + expect(bundled_app("gems.rb")).to be_file + end + + context "when gems.rb already exists" do + before do + create_file("gems.rb", <<-G) + gem "rails" + G + end + + it "does not change existing Gemfiles" do + expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) } + end + + it "notifies the user that an existing gems.rb already exists" do + bundle :init + expect(err).to include("gems.rb already exists") + end + end + + context "when a gems.rb file exists in a parent directory" do + let(:subdir) { "child_dir" } + + it "lets users generate a Gemfile in a child directory" do + bundle! :init + + FileUtils.mkdir bundled_app(subdir) + + Dir.chdir bundled_app(subdir) do + bundle! :init + end + + expect(out).to include("Writing new gems.rb") + expect(bundled_app("#{subdir}/gems.rb")).to be_file + end + end + + context "given --gemspec option" do let(:spec_file) { tmp.join("test.gemspec") } before do diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index b7ffc89a34..da31849be7 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "bundle inject", :bundler => "< 2" do +RSpec.describe "bundle inject", :bundler => "< 3" do before :each do gemfile <<-G source "file://#{gem_repo1}" @@ -37,14 +37,14 @@ RSpec.describe "bundle inject", :bundler => "< 2" do context "with injected gems already in the Gemfile" do it "doesn't add existing gems" do bundle "inject 'rack' '> 0'" - expect(out).to match(/cannot specify the same gem twice/i) + expect(err).to match(/cannot specify the same gem twice/i) end end context "incorrect arguments" do it "fails when more than 2 arguments are passed" do bundle "inject gem_name 1 v" - expect(out).to eq(<<-E.strip) + expect(err).to eq(<<-E.strip) ERROR: "bundle inject" was called with arguments ["gem_name", "1", "v"] Usage: "bundle inject GEM VERSION" E @@ -79,10 +79,10 @@ Usage: "bundle inject GEM VERSION" context "when frozen" do before do bundle "install" - if Bundler.feature_flag.bundler_2_mode? - bundle! "config --local deployment true" + if Bundler.feature_flag.bundler_3_mode? + bundle! "config set --local deployment true" else - bundle! "config --local frozen true" + bundle! "config set --local frozen true" end end @@ -109,7 +109,7 @@ Usage: "bundle inject GEM VERSION" gem "rack-obama" G bundle "inject 'rack' '> 0'" - expect(out).to match(/trying to install in deployment mode after changing/) + expect(err).to match(/trying to install in deployment mode after changing/) expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) end diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index c198797862..1a027a77c9 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -16,7 +16,7 @@ RSpec.describe "bundle install with gem sources" do raise StandardError, "FAIL" G - expect(last_command.bundler_err).to include('StandardError, "FAIL"') + expect(err).to include('StandardError, "FAIL"') expect(bundled_app("Gemfile.lock")).not_to exist end @@ -29,7 +29,7 @@ RSpec.describe "bundle install with gem sources" do expect(bundled_app("Gemfile.lock")).to exist end - it "does not create ./.bundle by default", :bundler => "< 2" do + it "does not create ./.bundle by default", :bundler => "< 3" do gemfile <<-G source "file://#{gem_repo1}" gem "rack" @@ -275,14 +275,14 @@ RSpec.describe "bundle install with gem sources" do expect(the_bundle).to include_gems "rack 1.0" end - it "allows running bundle install --system without deleting foo", :bundler => "< 2" do + it "allows running bundle install --system without deleting foo", :bundler => "< 3" do bundle "install", forgotten_command_line_options(:path => "vendor") bundle "install", forgotten_command_line_options(:system => true) FileUtils.rm_rf(bundled_app("vendor")) expect(the_bundle).to include_gems "rack 1.0" end - it "allows running bundle install --system after deleting foo", :bundler => "< 2" do + it "allows running bundle install --system after deleting foo", :bundler => "< 3" do bundle "install", forgotten_command_line_options(:path => "vendor") FileUtils.rm_rf(bundled_app("vendor")) bundle "install", forgotten_command_line_options(:system => true) @@ -290,7 +290,7 @@ RSpec.describe "bundle install with gem sources" do end end - it "finds gems in multiple sources", :bundler => "< 2" do + it "finds gems in multiple sources", :bundler => "< 3" do build_repo2 update_repo2 @@ -404,7 +404,7 @@ RSpec.describe "bundle install with gem sources" do G expect(last_command.stdboth).not_to match(/Error Report/i) - expect(last_command.bundler_err).to include("An error occurred while installing ajp-rails (0.0.0), and Bundler cannot continue."). + expect(err).to include("An error occurred while installing ajp-rails (0.0.0), and Bundler cannot continue."). and include(normalize_uri_file("Make sure that `gem install ajp-rails -v '0.0.0' --source 'file://localhost#{gem_repo2}/'` succeeds before bundling.")) end diff --git a/spec/commands/list_spec.rb b/spec/commands/list_spec.rb index fcce34cc72..346b47517e 100644 --- a/spec/commands/list_spec.rb +++ b/spec/commands/list_spec.rb @@ -1,15 +1,6 @@ # frozen_string_literal: true -RSpec.describe "bundle list", :bundler => "2" do - before do - install_gemfile <<-G - source "file://#{gem_repo1}" - - gem "rack" - gem "rspec", :group => [:test] - G - end - +RSpec.describe "bundle list" do context "with name-only and paths option" do it "raises an error" do bundle "list --name-only --paths" @@ -27,6 +18,15 @@ RSpec.describe "bundle list", :bundler => "2" do end describe "with without-group option" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + gem "rspec", :group => [:test] + G + end + context "when group is present" do it "prints the gems not in the specified group" do bundle! "list --without-group test" @@ -46,6 +46,15 @@ RSpec.describe "bundle list", :bundler => "2" do end describe "with only-group option" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + gem "rspec", :group => [:test] + G + end + context "when group is present" do it "prints the gems in the specified group" do bundle! "list --only-group default" @@ -65,6 +74,15 @@ RSpec.describe "bundle list", :bundler => "2" do end context "with name-only option" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + gem "rspec", :group => [:test] + G + end + it "prints only the name of the gems in the bundle" do bundle "list --name-only" @@ -82,7 +100,6 @@ RSpec.describe "bundle list", :bundler => "2" do build_git "git_test", "1.0.0", :path => lib_path("git_test") build_lib("gemspec_test", :path => tmp.join("gemspec_test")) do |s| - s.write("Gemfile", "source :rubygems\ngemspec") s.add_dependency "bar", "=1.0.0" end @@ -93,8 +110,6 @@ RSpec.describe "bundle list", :bundler => "2" do gem "git_test", :git => "#{lib_path("git_test")}" gemspec :path => "#{tmp.join("gemspec_test")}" G - - bundle! "install" end it "prints the path of each gem in the bundle" do @@ -119,13 +134,35 @@ RSpec.describe "bundle list", :bundler => "2" do end end - it "lists gems installed in the bundle" do - bundle "list" - expect(out).to include(" * rack (1.0.0)") + context "without options" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + gem "rspec", :group => [:test] + G + end + + it "lists gems installed in the bundle" do + bundle "list" + expect(out).to include(" * rack (1.0.0)") + end end - it "aliases the ls command to list" do - bundle "ls" - expect(out).to include("Gems included by the bundle") + context "when using the ls alias" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + gem "rspec", :group => [:test] + G + end + + it "runs the list command" do + bundle "ls" + expect(out).to include("Gems included by the bundle") + end end end diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb index f876d719cc..7aaf5c178e 100644 --- a/spec/commands/lock_spec.rb +++ b/spec/commands/lock_spec.rb @@ -242,7 +242,7 @@ RSpec.describe "bundle lock" do it "errors when removing all platforms" do bundle "lock --remove-platform #{local_platforms.join(" ")}" - expect(last_command.bundler_err).to include("Removing all platforms from the bundle is not allowed") + expect(err).to include("Removing all platforms from the bundle is not allowed") end # from https://github.com/bundler/bundler/issues/4896 diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 0d1058ad11..dcd36d3fe4 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -178,7 +178,7 @@ RSpec.describe "bundle gem" do end end - it "generates a valid gemspec" do + it "generates a valid gemspec", :ruby_repo do in_app_root bundle! "gem newgem --bin" @@ -770,22 +770,22 @@ RSpec.describe "bundle gem" do it "fails gracefully with a ." do bundle "gem foo.gemspec" - expect(last_command.bundler_err).to end_with("Invalid gem name foo.gemspec -- `Foo.gemspec` is an invalid constant name") + expect(err).to end_with("Invalid gem name foo.gemspec -- `Foo.gemspec` is an invalid constant name") end it "fails gracefully with a ^" do bundle "gem ^" - expect(last_command.bundler_err).to end_with("Invalid gem name ^ -- `^` is an invalid constant name") + expect(err).to end_with("Invalid gem name ^ -- `^` is an invalid constant name") end it "fails gracefully with a space" do bundle "gem 'foo bar'" - expect(last_command.bundler_err).to end_with("Invalid gem name foo bar -- `Foo bar` is an invalid constant name") + expect(err).to end_with("Invalid gem name foo bar -- `Foo bar` is an invalid constant name") end it "fails gracefully when multiple names are passed" do bundle "gem foo bar baz" - expect(last_command.bundler_err).to eq(<<-E.strip) + expect(err).to eq(<<-E.strip) ERROR: "bundle gem" was called with arguments ["foo", "bar", "baz"] Usage: "bundle gem NAME [OPTIONS]" E @@ -876,7 +876,7 @@ Usage: "bundle gem NAME [OPTIONS]" FileUtils.touch("conflict-foobar") end bundle "gem conflict-foobar" - expect(last_command.bundler_err).to include("Errno::ENOTDIR") + expect(err).to include("Errno::ENOTDIR") expect(exitstatus).to eql(32) if exitstatus end end @@ -887,7 +887,7 @@ Usage: "bundle gem NAME [OPTIONS]" FileUtils.mkdir_p("conflict-foobar/Gemfile") end bundle! "gem conflict-foobar" - expect(last_command.stdout).to include("file_clash conflict-foobar/Gemfile"). + expect(out).to include("file_clash conflict-foobar/Gemfile"). and include "Initializing git repo in #{bundled_app("conflict-foobar")}" end end diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 6d43f50d74..f0c2927218 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -206,7 +206,7 @@ RSpec.describe "bundle outdated" do build_gem "activesupport", "2.3.4" end - bundle! "config clean false" + bundle! "config set clean false" install_gemfile <<-G source "file://#{gem_repo2}" @@ -418,12 +418,12 @@ RSpec.describe "bundle outdated" do gem "foo" G - bundle "config auto_install 1" + bundle "config set auto_install 1" bundle :outdated expect(out).to include("Installing foo 1.0") end - context "after bundle install --deployment", :bundler => "< 2" do + context "after bundle install --deployment", :bundler => "< 3" do before do install_gemfile <<-G, forgotten_command_line_options(:deployment => true) source "file://#{gem_repo2}" diff --git a/spec/commands/package_spec.rb b/spec/commands/package_spec.rb index db8a96005c..b9cc079c5c 100644 --- a/spec/commands/package_spec.rb +++ b/spec/commands/package_spec.rb @@ -141,7 +141,7 @@ RSpec.describe "bundle package" do end end - context "with --path", :bundler => "< 2" do + context "with --path", :bundler => "< 3" do it "sets root directory for gems" do gemfile <<-D source "file://#{gem_repo1}" @@ -179,6 +179,18 @@ RSpec.describe "bundle package" do expect(the_bundle).to include_gems "rack 1.0.0" end + + it "does not prevent installing gems with bundle update" do + gemfile <<-D + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + D + + bundle! "package --no-install" + bundle! "update --all" + + expect(the_bundle).to include_gems "rack 1.0.0" + end end context "with --all-platforms" do @@ -205,7 +217,7 @@ RSpec.describe "bundle package" do subject { bundle :package, forgotten_command_line_options(:frozen => true) } it "tries to install with frozen" do - bundle! "config deployment true" + bundle! "config set deployment true" gemfile <<-G source "file://#{gem_repo1}" gem "rack" @@ -266,7 +278,7 @@ RSpec.describe "bundle install with gem sources" do end bundle :install - expect(last_command.stderr).to be_empty + expect(err).to be_empty expect(the_bundle).to include_gems "rack 1.0" end diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index d747fb9844..93eb81f2af 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -48,7 +48,14 @@ RSpec.describe "bundle pristine", :ruby_repo do bundle! "install" bundle! "pristine", :system_bundler => true bundle! "-v", :system_bundler => true - expect(out).to end_with(Bundler::VERSION) + + expected = if Bundler::VERSION < "3.0" + "Bundler version" + else + Bundler::VERSION + end + + expect(out).to start_with(expected) end end diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb index 298618747f..6e1986e35f 100644 --- a/spec/commands/show_spec.rb +++ b/spec/commands/show_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "bundle show" do +RSpec.describe "bundle show", :bundler => "< 3" do context "with a standard Gemfile" do before :each do install_gemfile <<-G @@ -30,7 +30,7 @@ RSpec.describe "bundle show" do expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end - it "prints deprecation", :bundler => "2" do + it "prints deprecation" do bundle "show rails" expect(err).to eq("[DEPRECATED] use `bundle info rails` instead of `bundle show rails`") end @@ -40,7 +40,7 @@ RSpec.describe "bundle show" do expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end - it "prints deprecation when called with a gem and the --paths option", :bundler => "2" do + it "prints deprecation when called with a gem and the --paths option" do bundle "show rails --paths" expect(err).to eq("[DEPRECATED] use `bundle info rails --path` instead of `bundle show rails --paths`") end @@ -59,7 +59,7 @@ RSpec.describe "bundle show" do expect(out).to eq(root.to_s) end - it "prints deprecation when called with bundler", :bundler => "2" do + it "prints deprecation when called with bundler" do bundle "show bundler" expect(err).to eq("[DEPRECATED] use `bundle info bundler` instead of `bundle show bundler`") end @@ -79,7 +79,7 @@ RSpec.describe "bundle show" do expect(gem_list).to eq(gem_list.sort) end - it "prints a deprecation when called with the --paths option", :bundler => 2 do + it "prints a deprecation when called with the --paths option" do bundle "show --paths" expect(err).to eq("[DEPRECATED] use `bundle list` instead of `bundle show --paths`") @@ -172,6 +172,19 @@ RSpec.describe "bundle show" do expect(out).to include("Installing foo 1.0") end + context "with a valid regexp for gem name" do + it "presents alternatives", :ruby_repo do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rack-obama" + G + + bundle "show rac" + expect(out).to eq "1 : rack\n2 : rack-obama\n0 : - exit -\n>" + end + end + context "with an invalid regexp for gem name" do it "does not find the gem" do install_gemfile <<-G @@ -213,3 +226,7 @@ RSpec.describe "bundle show" do end end end + +RSpec.describe "bundle show", :bundler => "3" do + pending "shows a friendly error about the command removal" +end diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb index 25e4401e7b..735d8cd8de 100644 --- a/spec/commands/update_spec.rb +++ b/spec/commands/update_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "bundle update" do G end - describe "with no arguments", :bundler => "< 2" do + describe "with no arguments", :bundler => "< 3" do it "updates the entire bundle" do update_repo2 do build_gem "activesupport", "3.0" @@ -35,7 +35,7 @@ RSpec.describe "bundle update" do end end - describe "with --all", :bundler => "2" do + describe "with --all", :bundler => "3" do it "updates the entire bundle" do update_repo2 do build_gem "activesupport", "3.0" @@ -65,14 +65,14 @@ RSpec.describe "bundle update" do gem "rack", "1.0" G - bundle! "update --gemfile OmgFile", :all => bundle_update_requires_all? + bundle! "update --gemfile OmgFile", :all => true expect(bundled_app("OmgFile.lock")).to exist end end context "when update_requires_all_flag is set" do - before { bundle! "config update_requires_all_flag true" } + before { bundle! "config set update_requires_all_flag true" } it "errors when passed nothing" do install_gemfile! "" @@ -133,7 +133,7 @@ RSpec.describe "bundle update" do describe "when a possible resolve requires an older version of a locked gem" do context "and only_update_to_newer_versions is set" do before do - bundle! "config only_update_to_newer_versions true" + bundle! "config set only_update_to_newer_versions true" end it "does not go to an older version" do @@ -167,7 +167,7 @@ RSpec.describe "bundle update" do end end - bundle! "update", :all => bundle_update_requires_all? + bundle! "update", :all => true expect(the_bundle).to include_gems("slim 3.0.9", "slim-rails 3.1.3", "slim_lint 0.16.1") end @@ -280,32 +280,32 @@ RSpec.describe "bundle update" do end describe "in a frozen bundle" do - it "should fail loudly", :bundler => "< 2" do + it "should fail loudly", :bundler => "< 3" do bundle! "install --deployment" - bundle "update", :all => bundle_update_requires_all? + bundle "update", :all => true expect(last_command).to be_failure - expect(out).to match(/You are trying to install in deployment mode after changing.your Gemfile/m) - expect(out).to match(/freeze \nby running `bundle install --no-deployment`./m) + expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m) + expect(err).to match(/freeze \nby running `bundle install --no-deployment`./m) end - it "should suggest different command when frozen is set globally", :bundler => "< 2" do - bundle! "config --global frozen 1" - bundle "update", :all => bundle_update_requires_all? - expect(out).to match(/You are trying to install in deployment mode after changing.your Gemfile/m). + it "should suggest different command when frozen is set globally", :bundler => "< 3" do + bundle! "config set --global frozen 1" + bundle "update", :all => true + expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m). and match(/freeze \nby running `bundle config unset frozen`./m) end - it "should suggest different command when frozen is set globally", :bundler => "2" do - bundle! "config --global deployment true" - bundle "update", :all => bundle_update_requires_all? + it "should suggest different command when frozen is set globally", :bundler => "3" do + bundle! "config set --global deployment true" + bundle "update", :all => true expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m). and match(/freeze \nby running `bundle config unset deployment`./m) end end describe "with --source option" do - it "should not update gems not included in the source that happen to have the same name", :bundler => "< 2" do + it "should not update gems not included in the source that happen to have the same name", :bundler => "< 3" do install_gemfile! <<-G source "file://#{gem_repo2}" gem "activesupport" @@ -316,7 +316,7 @@ RSpec.describe "bundle update" do expect(the_bundle).to include_gem "activesupport 3.0" end - it "should not update gems not included in the source that happen to have the same name", :bundler => "2" do + it "should not update gems not included in the source that happen to have the same name", :bundler => "3" do install_gemfile! <<-G source "file://#{gem_repo2}" gem "activesupport" @@ -328,7 +328,7 @@ RSpec.describe "bundle update" do end context "with unlock_source_unlocks_spec set to false" do - before { bundle! "config unlock_source_unlocks_spec false" } + before { bundle! "config set unlock_source_unlocks_spec false" } it "should not update gems not included in the source that happen to have the same name" do install_gemfile <<-G @@ -359,7 +359,7 @@ RSpec.describe "bundle update" do G end - it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "< 2" do + it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "< 3" do update_repo2 do build_gem "fred", "2.0" build_gem "harry", "2.0" do |s| @@ -372,7 +372,7 @@ RSpec.describe "bundle update" do expect(the_bundle).to include_gems "fred 1.0" end - it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "2" do + it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "3" do update_repo2 do build_gem "fred", "2.0" build_gem "harry", "2.0" do |s| @@ -404,7 +404,7 @@ RSpec.describe "bundle update" do G end - it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "< 2" do + it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "< 3" do update_repo2 do build_gem "george", "2.0" build_gem "harry", "2.0" do |s| @@ -418,7 +418,7 @@ RSpec.describe "bundle update" do expect(the_bundle).to include_gems "george 1.0" end - it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "2" do + it "should not update the child dependencies of a gem that has the same name as the source", :bundler => "3" do update_repo2 do build_gem "george", "2.0" build_gem "harry", "2.0" do |s| @@ -473,6 +473,39 @@ RSpec.describe "bundle update in more complicated situations" do expect(the_bundle).to include_gems "thin 2.0", "rack 10.0", "rack-obama 1.0" end + it "will not warn when an explicitly updated git gem changes sha but not version" do + build_git "foo" + + install_gemfile! <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + + update_git "foo" do |s| + s.write "lib/foo2.rb", "puts :foo2" + end + + bundle! "update foo" + + expect(last_command.stdboth).not_to include "attempted to update" + end + + it "will not warn when changing gem sources but not versions" do + build_git "rack" + + install_gemfile! <<-G + gem "rack", :git => '#{lib_path("rack-1.0")}' + G + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle! "update rack" + + expect(last_command.stdboth).not_to include "attempted to update" + end + it "will update only from pinned source" do install_gemfile <<-G source "file://#{gem_repo2}" @@ -542,7 +575,7 @@ RSpec.describe "bundle update without a Gemfile.lock" do gem "rack", "1.0" G - bundle "update", :all => bundle_update_requires_all? + bundle "update", :all => true expect(the_bundle).to include_gems "rack 1.0.0" end @@ -562,23 +595,23 @@ RSpec.describe "bundle update when a gem depends on a newer version of bundler" G end - it "should explain that bundler conflicted", :bundler => "< 2" do - bundle "update", :all => bundle_update_requires_all? + it "should explain that bundler conflicted", :bundler => "< 3" do + bundle "update", :all => true expect(last_command.stdboth).not_to match(/in snapshot/i) - expect(last_command.bundler_err).to match(/current Bundler version/i). + expect(err).to match(/current Bundler version/i). and match(/perhaps you need to update bundler/i) end - it "should warn that the newer version of Bundler would conflict", :bundler => "2" do + it "should warn that the newer version of Bundler would conflict", :bundler => "3" do bundle! "update", :all => true - expect(last_command.bundler_err).to include("rails (3.0.1) has dependency bundler"). + expect(err).to include("rails (3.0.1) has dependency bundler"). and include("so the dependency is being ignored") expect(the_bundle).to include_gem "rails 3.0.1" end end RSpec.describe "bundle update" do - it "shows the previous version of the gem when updated from rubygems source", :bundler => "< 2" do + it "shows the previous version of the gem when updated from rubygems source", :bundler => "< 3" do build_repo2 install_gemfile <<-G @@ -586,19 +619,19 @@ RSpec.describe "bundle update" do gem "activesupport" G - bundle "update", :all => bundle_update_requires_all? + bundle "update", :all => true expect(out).to include("Using activesupport 2.3.5") update_repo2 do build_gem "activesupport", "3.0" end - bundle "update", :all => bundle_update_requires_all? + bundle "update", :all => true expect(out).to include("Installing activesupport 3.0 (was 2.3.5)") end context "with suppress_install_using_messages set" do - before { bundle! "config suppress_install_using_messages true" } + before { bundle! "config set suppress_install_using_messages true" } it "only prints `Using` for versions that have changed" do build_repo4 do @@ -612,7 +645,7 @@ RSpec.describe "bundle update" do gem "foo" G - bundle! "update", :all => bundle_update_requires_all? + bundle! "update", :all => true out.gsub!(/RubyGems [\d\.]+ is not threadsafe.*\n?/, "") expect(out).to include "Resolving dependencies...\nBundle updated!" @@ -620,7 +653,7 @@ RSpec.describe "bundle update" do build_gem "foo", "2.0" end - bundle! "update", :all => bundle_update_requires_all? + bundle! "update", :all => true out.sub!("Removing foo (1.0)\n", "") out.gsub!(/RubyGems [\d\.]+ is not threadsafe.*\n?/, "") expect(out).to include strip_whitespace(<<-EOS).strip @@ -811,7 +844,7 @@ RSpec.describe "bundle update conservative" do context "with patch set as default update level in config" do it "should do a patch level update" do - bundle! "config --local prefer_patch true" + bundle! "config set --local prefer_patch true" bundle! "update foo" expect(the_bundle).to include_gems "foo 1.4.5", "bar 2.1.1", "qux 1.0.0" @@ -826,7 +859,7 @@ RSpec.describe "bundle update conservative" do end it "update all" do - bundle! "update --patch", :all => bundle_update_requires_all? + bundle! "update --patch", :all => true expect(the_bundle).to include_gems "foo 1.4.5", "bar 2.1.1", "qux 1.0.1" end @@ -848,7 +881,7 @@ RSpec.describe "bundle update conservative" do end it "minor preferred" do - bundle! "update --minor --strict", :all => bundle_update_requires_all? + bundle! "update --minor --strict", :all => true expect(the_bundle).to include_gems "foo 1.5.0", "bar 2.1.1", "qux 1.1.0" end @@ -945,9 +978,9 @@ RSpec.describe "bundle update conservative" do end it "raises if too many flags are provided" do - bundle "update --patch --minor", :all => bundle_update_requires_all? + bundle "update --patch --minor", :all => true - expect(last_command.bundler_err).to eq "Provide only one of the following options: minor, patch" + expect(err).to eq "Provide only one of the following options: minor, patch" end end end diff --git a/spec/commands/version_spec.rb b/spec/commands/version_spec.rb index b919c25e0f..66c7930397 100644 --- a/spec/commands/version_spec.rb +++ b/spec/commands/version_spec.rb @@ -2,36 +2,36 @@ RSpec.describe "bundle version" do context "with -v" do - it "outputs the version", :bundler => "< 2" do + it "outputs the version", :bundler => "< 3" do bundle! "-v" expect(out).to eq("Bundler version #{Bundler::VERSION}") end - it "outputs the version", :bundler => "2" do + it "outputs the version", :bundler => "3" do bundle! "-v" expect(out).to eq(Bundler::VERSION) end end context "with --version" do - it "outputs the version", :bundler => "< 2" do + it "outputs the version", :bundler => "< 3" do bundle! "--version" expect(out).to eq("Bundler version #{Bundler::VERSION}") end - it "outputs the version", :bundler => "2" do + it "outputs the version", :bundler => "3" do bundle! "--version" expect(out).to eq(Bundler::VERSION) end end context "with version" do - it "outputs the version with build metadata", :bundler => "< 2" do + it "outputs the version with build metadata", :bundler => "< 3" do bundle! "version" expect(out).to match(/\ABundler version #{Regexp.escape(Bundler::VERSION)} \(\d{4}-\d{2}-\d{2} commit [a-fA-F0-9]{7,}\)\z/) end - it "outputs the version with build metadata", :bundler => "2" do + it "outputs the version with build metadata", :bundler => "3" do bundle! "version" expect(out).to match(/\A#{Regexp.escape(Bundler::VERSION)} \(\d{4}-\d{2}-\d{2} commit [a-fA-F0-9]{7,}\)\z/) end |