aboutsummaryrefslogtreecommitdiffstats
path: root/spec/bundler/commands/binstubs_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/commands/binstubs_spec.rb')
-rw-r--r--spec/bundler/commands/binstubs_spec.rb168
1 files changed, 149 insertions, 19 deletions
diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb
index cb0999348e..0313f48b60 100644
--- a/spec/bundler/commands/binstubs_spec.rb
+++ b/spec/bundler/commands/binstubs_spec.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-require "spec_helper"
RSpec.describe "bundle binstubs <gem>" do
context "when the gem exists in the lockfile" do
@@ -51,22 +50,130 @@ 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", <<-R
+ specs = Gem.loaded_specs.values.reject {|s| Bundler.rubygems.spec_default_gem?(s) }
+ puts specs.map(&:full_name).sort.inspect
+ R
+ 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
+ simulate_bundler_version "55"
+ 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:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '44.0'`")
+ end
+
+ it "runs the correct version of bundler when the version is a pre-release" do
+ simulate_bundler_version "55"
+ 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:").
+ and include("To install the version of bundler this project requires, run `gem install bundler -v '2.12.0.a'`")
+ end
+ end
+
+ 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! "#{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
+
+ 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", :ruby_repo 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
- bundle "binstubs bundler"
+ context "when requesting a different bundler version" do
+ before { lockfile lockfile.gsub(Bundler::VERSION, "999.999.999") }
- expect(bundled_app("bin/bundle")).not_to exist
- expect(out).to include("Sorry, Bundler can only be run via Rubygems.")
+ 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
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|
- s.executables = %w(foo)
+ s.executables = %w[foo]
end
install_gemfile <<-G
gem "foo", :git => "#{lib_path("foo")}"
@@ -81,7 +188,7 @@ RSpec.describe "bundle binstubs <gem>" 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|
- s.executables = %w(foo)
+ s.executables = %w[foo]
end
install_gemfile <<-G
gem "foo", :path => "#{lib_path("foo")}"
@@ -104,6 +211,19 @@ RSpec.describe "bundle binstubs <gem>" do
expect(File.stat(binary).mode.to_s(8)).to eq("100775")
end
end
+
+ context "when using --shebang" do
+ it "sets the specified shebang for the the binstub" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ bundle "binstubs rack --shebang jruby"
+
+ expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env jruby\n")
+ end
+ end
end
context "when the gem doesn't exist" do
@@ -131,33 +251,43 @@ RSpec.describe "bundle binstubs <gem>" do
expect(bundled_app("exec/rackup")).to exist
end
- it "setting is saved for bundle install" do
+ it "setting is saved for bundle install", :bundler => "< 2" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
gem "rails"
G
- bundle "binstubs rack --path exec"
- bundle :install
+ bundle! "binstubs rack", forgotten_command_line_options([:path, :bin] => "exec")
+ bundle! :install
expect(bundled_app("exec/rails")).to exist
end
end
- context "after installing with --standalone" do
+ context "with --standalone option" do
before do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
G
- bundle "install --standalone"
end
- it "includes the standalone path" do
- bundle "binstubs rack --standalone"
- standalone_line = File.read(bundled_app("bin/rackup")).each_line.find {|line| line.include? "$:.unshift" }.strip
- expect(standalone_line).to eq %($:.unshift File.expand_path "../../bundle", path.realpath)
+ it "generates a standalone binstub" do
+ bundle! "binstubs rack --standalone"
+ expect(bundled_app("bin/rackup")).to exist
+ end
+
+ it "generates a binstub that does not depend on rubygems or bundler" do
+ bundle! "binstubs rack --standalone"
+ expect(File.read(bundled_app("bin/rackup"))).to_not include("Gem.bin_path")
+ end
+
+ context "when specified --path option" do
+ it "generates a standalone binstub at the given path" do
+ bundle! "binstubs rack --standalone --path foo"
+ expect(bundled_app("foo/rackup")).to exist
+ end
end
end