diff options
author | Homu <homu@barosl.com> | 2016-06-11 12:03:38 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-06-11 12:03:38 +0900 |
commit | 13f64fa210edbf92f3281e4055e88a37437d0486 (patch) | |
tree | 71df1d14b0f81c1c1d17c41e06c295f46f0c0f3e /spec | |
parent | 5a80fcfea13c97baad4935df9c323fb67d499877 (diff) | |
parent | deb5a149134a6366de70187a85ae67d582397797 (diff) | |
download | bundler-13f64fa210edbf92f3281e4055e88a37437d0486.tar.gz |
Auto merge of #4643 - bundler:seg-postit-trampoline, r=indirect
[bundle] Automatically trampoline to postit
- [x] Specs
~~Except on bundle exec, since that would be too slow~~
~~If you want, I guess we could vendor postit and manually setup the `LOAD_PATH` and `-r` the full path to the vendored postit exe. Your call.~~ Done this
\c @indirect
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/shared_helpers_spec.rb | 2 | ||||
-rw-r--r-- | spec/other/trampoline_spec.rb | 137 | ||||
-rw-r--r-- | spec/support/helpers.rb | 1 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 3 |
4 files changed, 141 insertions, 2 deletions
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index 98f7994f..2ad0c98d 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -222,7 +222,7 @@ describe Bundler::SharedHelpers do shared_examples_for "ENV['RUBYOPT'] gets set correctly" do it "ensures -rbundler/setup is at the beginning of ENV['RUBYOPT']" do subject.set_bundle_environment - expect(ENV["RUBYOPT"].split(" ").first).to include("-rbundler/setup") + expect(ENV["RUBYOPT"].split(" ")).to start_with("-rbundler/setup") end end diff --git a/spec/other/trampoline_spec.rb b/spec/other/trampoline_spec.rb new file mode 100644 index 00000000..640c6085 --- /dev/null +++ b/spec/other/trampoline_spec.rb @@ -0,0 +1,137 @@ +# frozen_string_literal: true +require "spec_helper" + +describe "bundler version trampolining" do + before do + ENV["BUNDLE_DISABLE_POSTIT"] = nil + FileUtils.rm_rf(system_gem_path) + FileUtils.cp_r(base_system_gems, system_gem_path) + end + + context "version guessing" do + shared_examples_for "guesses" do |version| + it "guesses the correct bundler version" do + bundle! "--version" + expect(out).to eq("Bundler version #{version}") + + if bundled_app("Gemfile").file? + bundle! "exec ruby -e 'puts Bundler::VERSION'" + expect(out).to eq(version) + end + end + end + + context "with a lockfile" do + before do + install_gemfile "" + lockfile lockfile.sub(Bundler::VERSION, "1.12.0") + end + + include_examples "guesses", "1.12.0" + end + + context "with BUNDLER_VERSION" do + before do + ENV["BUNDLER_VERSION"] = "1.12.0" + end + + context "with a lockfile" do + before { install_gemfile "" } + include_examples "guesses", "1.12.0" + end + + context "without a lockfile" do + include_examples "guesses", "1.12.0" + end + end + + context "with no hints" do + include_examples "guesses", Bundler::VERSION + end + + context "with a gemfile and no lockfile" do + before do + gemfile "" + end + + include_examples "guesses", Bundler::VERSION + end + end + + context "installing missing bundler versions", :realworld => true do + before do + ENV["BUNDLER_VERSION"] = "1.12.3" + if Bundler::RubygemsIntegration.provides?("< 2.6.4") + # necessary since we intall with 2.6.4 but the specs can run against + # older versions that match againt the "gem" invocation + %w(bundle bundler).each do |exe| + system_gem_path.join("bin", exe).open("a") do |f| + f << %(\ngem "bundler", ">= 0.a"\n) + end + end + end + end + + it "guesses & installs the correct bundler version" do + expect(system_gem_path.join("gems", "bundler-1.12.3")).not_to exist + bundle! "--version" + expect(out).to eq("Bundler version 1.12.3") + expect(system_gem_path.join("gems", "bundler-1.12.3")).to exist + end + + it "fails gracefully when installing the bundler fails" do + ENV["BUNDLER_VERSION"] = "9999" + bundle "--version", :expect_err => true + expect(err).to start_with(<<-E.strip) +Installing the inferred bundler version (= 9999) failed. +If you'd like to update to the current bundler version (1.12.5) in this project, run `bundle update --bundler`. +The error was: + E + end + end + + context "bundle update --bundler" do + before do + simulate_bundler_version("1.11.1") do + install_gemfile "" + end + end + + it "updates to the specified version" do + # HACK: since no released bundler version actually supports this feature! + bundle "update --bundler=1.12.0", :expect_err => true + expect(out).to include("Unknown switches '--bundler=1.12.0'") + end + + it "updates to the specified (running) version" do + # HACK: since no released bundler version actually supports this feature! + bundle! "update --bundler=#{Bundler::VERSION}" + bundle! "--version" + expect(out).to eq("Bundler version #{Bundler::VERSION}") + end + + it "updates to the running version" do + # HACK: since no released bundler version actually supports this feature! + bundle! "update --bundler" + bundle! "--version" + expect(out).to eq("Bundler version #{Bundler::VERSION}") + end + end + + context "-rbundler/setup" do + before do + simulate_bundler_version("1.12.0") do + install_gemfile "" + end + end + + it "uses the locked version" do + ruby! <<-R + require "bundler/setup" + puts Bundler::VERSION + R + expect(err).to be_empty + expect(out).to eq("1.12.0") + end + end +end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index ff41dfbf..704e2140 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -12,6 +12,7 @@ module Spec end FileUtils.mkdir_p(tmp) FileUtils.mkdir_p(home) + ENV["BUNDLE_DISABLE_POSTIT"] = "1" Bundler.send(:remove_instance_variable, :@settings) if Bundler.send(:instance_variable_defined?, :@settings) end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index 64cc4144..95f596ea 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -11,7 +11,8 @@ module Spec # Rake version has to be consistent for tests to pass "rake" => "10.0.2", # 3.0.0 breaks 1.9.2 specs - "builder" => "2.1.2" + "builder" => "2.1.2", + "bundler" => "1.12.0", } # ruby-graphviz is used by the viz tests deps["ruby-graphviz"] = nil if RUBY_VERSION >= "1.9.3" |