diff options
Diffstat (limited to 'spec/commands/binstubs_spec.rb')
-rw-r--r-- | spec/commands/binstubs_spec.rb | 117 |
1 files changed, 110 insertions, 7 deletions
diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index 89fc3866f7..eb14db4f6f 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -50,15 +50,118 @@ RSpec.describe "bundle binstubs <gem>" do expect(out).to include("`bundle binstubs` needs at least one gem to run.") end - it "does not bundle the bundler binary" do - install_gemfile <<-G - source "file://#{gem_repo1}" - G + context "the bundle binstub" do + before do + if system_bundler_version == :bundler + system_gems :bundler + elsif system_bundler_version + build_repo4 do + build_gem "bundler", system_bundler_version do |s| + s.executables = "bundle" + s.bindir = "exe" + s.write "exe/bundle", "puts %(system bundler #{system_bundler_version}\\n\#{ARGV.inspect})" + end + end + system_gems "bundler-#{system_bundler_version}", :gem_repo => gem_repo4 + end + build_repo2 do + build_gem "prints_loaded_gems", "1.0" do |s| + s.executables = "print_loaded_gems" + s.write "bin/print_loaded_gems", 'puts "#{Gem.loaded_specs.values.reject(&:default_gem?).map(&:full_name).sort.inspect}"' + end + end + install_gemfile! <<-G + source "file://#{gem_repo2}" + gem "rack" + gem "prints_loaded_gems" + G + bundle! "binstubs bundler rack prints_loaded_gems" + end + + let(:system_bundler_version) { Bundler::VERSION } + + it "runs bundler" do + sys_exec! "#{bundled_app("bin/bundle")} install" + expect(out).to eq %(system bundler #{system_bundler_version}\n["install"]) + end + + context "when BUNDLER_VERSION is set" do + it "runs the correct version of bundler" do + sys_exec "BUNDLER_VERSION=999.999.999 #{bundled_app("bin/bundle")} install" + expect(exitstatus).to eq(42) if exitstatus + expect(last_command.stderr).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 + + context "when a lockfile exists with a locked bundler version" do + it "runs the correct version of bundler when the version is newer" 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:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") + end + + it "runs the correct version of bundler when the version is older" do + lockfile lockfile.gsub(system_bundler_version, "1.0") + sys_exec "#{bundled_app("bin/bundle")} install" + expect(exitstatus).to eq(42) if exitstatus + expect(last_command.stderr).to include("Activating bundler (1.0) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '1.0'`") + end + + it "runs the correct version of bundler when the version is a pre-release" do + lockfile lockfile.gsub(system_bundler_version, "1.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 (1.12.0.a) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '1.12.0.a'`") + end + end + + context "when update --bundler is called" do + before { lockfile.gsub(system_bundler_version, "1.1.1") } - bundle "binstubs bundler" + 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"]) + 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:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") + end + end - expect(bundled_app("bin/bundle")).not_to exist - expect(out).to include("Sorry, Bundler can only be run via RubyGems.") + context "without a lockfile" do + it "falls back to the latest installed bundler" do + FileUtils.rm bundled_app("Gemfile.lock") + sys_exec! bundled_app("bin/bundle").to_s + expect(out).to eq "system bundler #{system_bundler_version}\n[]" + end + end + + context "using another binstub" do + let(:system_bundler_version) { :bundler } + it "loads all gems" do + sys_exec! bundled_app("bin/print_loaded_gems").to_s + expect(out).to eq %(["bundler-#{Bundler::VERSION}", "prints_loaded_gems-1.0", "rack-1.2"]) + end + + context "when requesting a different bundler version" 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 + expect(exitstatus).to eq(42) if exitstatus + expect(last_command.stderr).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 + end end it "installs binstubs from git gems" do |