diff options
Diffstat (limited to 'spec/bundler/commands/binstubs_spec.rb')
-rw-r--r-- | spec/bundler/commands/binstubs_spec.rb | 125 |
1 files changed, 94 insertions, 31 deletions
diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index fb5da98bf3..6c3dc7bb2d 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -45,7 +45,7 @@ RSpec.describe "bundle binstubs <gem>" do gem "rails" G - bundle :binstubs, :all => true + bundle :binstubs, all: true expect(bundled_app("bin/rails")).to exist expect(bundled_app("bin/rake")).to exist @@ -69,7 +69,7 @@ RSpec.describe "bundle binstubs <gem>" do gem "rack" G - bundle "binstubs", :raise_on_error => false + bundle "binstubs", raise_on_error: false expect(exitstatus).to eq(1) expect(err).to include("`bundle binstubs` needs at least one gem to run.") end @@ -80,7 +80,7 @@ RSpec.describe "bundle binstubs <gem>" do gem "rack" G - bundle "binstubs rack", :all => true, :raise_on_error => false + bundle "binstubs rack", all: true, raise_on_error: false expect(last_command).to be_failure expect(err).to include("Cannot specify --all with specific gems") end @@ -98,7 +98,7 @@ RSpec.describe "bundle binstubs <gem>" do file.print "OMG" end - sys_exec "bin/rackup", :raise_on_error => false + sys_exec "bin/rackup", raise_on_error: false expect(err).to include("was not generated by Bundler") end @@ -116,7 +116,7 @@ RSpec.describe "bundle binstubs <gem>" do s.executables = "print_loaded_gems" s.bindir = "exe" s.write "exe/print_loaded_gems", <<-R - specs = Gem.loaded_specs.values.reject {|s| Bundler.rubygems.spec_default_gem?(s) } + specs = Gem.loaded_specs.values.reject {|s| s.default_gem? } puts specs.map(&:full_name).sort.inspect R end @@ -132,13 +132,13 @@ RSpec.describe "bundle binstubs <gem>" do let(:system_bundler_version) { Bundler::VERSION } it "runs bundler" do - sys_exec "bin/bundle install", :env => { "DEBUG" => "1" } + sys_exec "bin/bundle install", env: { "DEBUG" => "1" } expect(out).to include %(Using bundler #{system_bundler_version}\n) end context "when BUNDLER_VERSION is set" do it "runs the correct version of bundler" do - sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.999" }, :raise_on_error => false + sys_exec "bin/bundle install", env: { "BUNDLER_VERSION" => "999.999.999" }, raise_on_error: false expect(exitstatus).to eq(42) 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'`") @@ -147,7 +147,7 @@ RSpec.describe "bundle binstubs <gem>" do it "runs the correct version of bundler even if a higher version is installed" do system_gems "bundler-999.999.998", "bundler-999.999.999" - sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.998", "DEBUG" => "1" }, :raise_on_error => false + sys_exec "bin/bundle install", env: { "BUNDLER_VERSION" => "999.999.998", "DEBUG" => "1" }, raise_on_error: false expect(out).to include %(Using bundler 999.999.998\n) end end @@ -159,7 +159,22 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler" do - sys_exec "bin/bundle install", :raise_on_error => false + sys_exec "bin/bundle install", raise_on_error: false + expect(exitstatus).to eq(42) + expect(err).to include("Activating bundler (~> 999.999) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") + end + end + + context "and the version is newer when given `gems.rb` and `gems.locked`" do + before do + gemfile bundled_app("gems.rb"), gemfile + lockfile bundled_app("gems.locked"), lockfile.gsub(system_bundler_version, "999.999") + end + + it "runs the correct version of bundler" do + sys_exec "bin/bundle install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false + expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -174,7 +189,23 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler" do - sys_exec "bin/bundle install", :raise_on_error => false + sys_exec "bin/bundle install", raise_on_error: false + expect(exitstatus).to eq(42) + 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 + end + + context "and the version is older and a different major when given `gems.rb` and `gems.locked`" do + let(:system_bundler_version) { "55" } + + before do + gemfile bundled_app("gems.rb"), gemfile + lockfile bundled_app("gems.locked"), lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 44.0") + end + + it "runs the correct version of bundler" do + sys_exec "bin/bundle install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false expect(exitstatus).to eq(42) 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'`") @@ -182,16 +213,26 @@ RSpec.describe "bundle binstubs <gem>" do end context "and the version is older and the same major" do - let(:system_bundler_version) { "55.1" } + let(:system_bundler_version) { "2.999.999" } before do - lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 55.0") + lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 2.3.0") end - it "runs the available version of bundler when the version is older and the same major" do - sys_exec "bin/bundle install" + it "installs and runs the exact version of bundler", rubygems: ">= 3.3.0.dev", realworld: true do + sys_exec "bin/bundle install --verbose", artifice: "vcr" expect(exitstatus).not_to eq(42) - expect(err).not_to include("Activating bundler (~> 55.0) failed:") + expect(out).to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.") + expect(out).to include("Using bundler 2.3.0") + expect(err).not_to include("Activating bundler (~> 2.3.0) failed:") + end + + it "runs the available version of bundler", rubygems: "< 3.3.0.dev" do + sys_exec "bin/bundle install --verbose" + expect(exitstatus).not_to eq(42) + expect(out).not_to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.") + expect(out).to include("Using bundler 2.999.999") + expect(err).not_to include("Activating bundler (~> 2.3.0) failed:") end end @@ -203,7 +244,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler when the version is a pre-release" do - sys_exec "bin/bundle install", :raise_on_error => false + sys_exec "bin/bundle install", raise_on_error: false expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 2.12.a) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`") @@ -214,13 +255,16 @@ RSpec.describe "bundle binstubs <gem>" do context "when update --bundler is called" do before { lockfile.gsub(system_bundler_version, "1.1.1") } - it "calls through to the latest bundler version" do - sys_exec "bin/bundle update --bundler", :env => { "DEBUG" => "1" } - expect(out).to include %(Using bundler #{system_bundler_version}\n) + it "calls through to the latest bundler version", :realworld do + sys_exec "bin/bundle update --bundler", env: { "DEBUG" => "1" } + using_bundler_line = /Using bundler ([\w\.]+)\n/.match(out) + expect(using_bundler_line).to_not be_nil + latest_version = using_bundler_line[1] + expect(Gem::Version.new(latest_version)).to be >= Gem::Version.new(system_bundler_version) end it "calls through to the explicit bundler version" do - sys_exec "bin/bundle update --bundler=999.999.999", :raise_on_error => false + sys_exec "bin/bundle update --bundler=999.999.999", raise_on_error: false expect(exitstatus).to eq(42) 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'`") @@ -230,7 +274,7 @@ RSpec.describe "bundle binstubs <gem>" do context "without a lockfile" do it "falls back to the latest installed bundler" do FileUtils.rm bundled_app_lock - sys_exec "bin/bundle install", :env => { "DEBUG" => "1" } + sys_exec "bin/bundle install", env: { "DEBUG" => "1" } expect(out).to include "Using bundler #{system_bundler_version}\n" end end @@ -245,7 +289,7 @@ RSpec.describe "bundle binstubs <gem>" do before { lockfile lockfile.gsub(Bundler::VERSION, "999.999.999") } it "attempts to load that version" do - sys_exec bundled_app("bin/rackup").to_s, :raise_on_error => false + sys_exec bundled_app("bin/rackup").to_s, raise_on_error: false expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -257,7 +301,7 @@ RSpec.describe "bundle binstubs <gem>" do it "installs binstubs from git gems" do FileUtils.mkdir_p(lib_path("foo/bin")) FileUtils.touch(lib_path("foo/bin/foo")) - build_git "foo", "1.0", :path => lib_path("foo") do |s| + build_git "foo", "1.0", path: lib_path("foo") do |s| s.executables = %w[foo] end install_gemfile <<-G @@ -273,7 +317,7 @@ RSpec.describe "bundle binstubs <gem>" do it "installs binstubs from path gems" do FileUtils.mkdir_p(lib_path("foo/bin")) FileUtils.touch(lib_path("foo/bin/foo")) - build_lib "foo", "1.0", :path => lib_path("foo") do |s| + build_lib "foo", "1.0", path: lib_path("foo") do |s| s.executables = %w[foo] end install_gemfile <<-G @@ -287,8 +331,6 @@ RSpec.describe "bundle binstubs <gem>" do end it "sets correct permissions for binstubs" do - skip "https://github.com/rubygems/rubygems/issues/3352" if Gem.win_platform? - with_umask(0o002) do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -297,7 +339,7 @@ RSpec.describe "bundle binstubs <gem>" do bundle "binstubs rack" binary = bundled_app("bin/rackup") - expect(File.stat(binary).mode.to_s(8)).to eq("100775") + expect(File.stat(binary).mode.to_s(8)).to eq(Gem.win_platform? ? "100644" : "100775") end end @@ -320,7 +362,7 @@ RSpec.describe "bundle binstubs <gem>" do source "#{file_uri_for(gem_repo1)}" G - bundle "binstubs doesnt_exist", :raise_on_error => false + bundle "binstubs doesnt_exist", raise_on_error: false expect(exitstatus).to eq(7) expect(err).to include("Could not find gem 'doesnt_exist'.") @@ -339,14 +381,14 @@ RSpec.describe "bundle binstubs <gem>" do expect(bundled_app("exec/rackup")).to exist end - it "setting is saved for bundle install", :bundler => "< 3" do + it "setting is saved for bundle install", bundler: "< 3" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" gem "rails" G - bundle "binstubs rack", :path => "exec" + bundle "binstubs rack", path: "exec" bundle :install expect(bundled_app("exec/rails")).to exist @@ -358,6 +400,7 @@ RSpec.describe "bundle binstubs <gem>" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" + gem "rails" G end @@ -385,6 +428,26 @@ RSpec.describe "bundle binstubs <gem>" do expect(bundled_app("bin/rackup.cmd")).to exist end end + + context "when the gem is bundler" do + it "warns without generating a standalone binstub" do + bundle "binstubs bundler --standalone" + expect(bundled_app("bin/bundle")).not_to exist + expect(bundled_app("bin/bundler")).not_to exist + expect(err).to include("Sorry, Bundler can only be run via RubyGems.") + end + end + + context "when specified --all option" do + it "generates standalone binstubs for all gems except bundler" do + bundle "binstubs --standalone --all" + expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/rails")).to exist + expect(bundled_app("bin/bundle")).not_to exist + expect(bundled_app("bin/bundler")).not_to exist + expect(err).not_to include("Sorry, Bundler can only be run via RubyGems.") + end + end end context "when the bin already exists" do @@ -486,7 +549,7 @@ RSpec.describe "bundle binstubs <gem>" do G bundle "config set auto_install 1" - bundle "binstubs rack", :env => { "BUNDLE_INSTALL" => "1" } + bundle "binstubs rack", env: { "BUNDLE_INSTALL" => "1" } expect(out).not_to include("Installing rack 1.0.0") end end |