diff options
author | The Bundler Bot <bot@bundler.io> | 2017-06-27 14:56:22 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-06-27 14:56:22 +0000 |
commit | 85258353a1592fb3862343f3a4cb7e3163445015 (patch) | |
tree | 7449779cad825324f1037523143bb789603ff566 | |
parent | a14b5c02da80dc74bdafc660f592c5c4d0c8740d (diff) | |
parent | a779cf00476acd535c6b7a71467fdbd09e4f6d50 (diff) | |
download | bundler-85258353a1592fb3862343f3a4cb7e3163445015.tar.gz |
Auto merge of #5815 - gxespino:non-absolute-paths, r=segiddins
Allow BUNDLE_GEMFILE to not be an absolute path
Hello - I was stalking the open issues and had time to implement this quick PR for your review. This is a direct fix to https://github.com/bundler/bundler/issues/5712.
I implemented the fix that @segiddins suggested in the comments, just added a test scenario. Please let me know if anything else is needed!
---
### What was the end-user problem that led to this PR?
The problem was that starting with Bundler 1.15.0, `Bundler.setup` fails with an `ArgumentError` raised from `Pathname#relative_path_from` when the following conditions are met:
- Bundler is in deployment mode; and
- A Gemfile is explicitly specified via the `BUNDLE_GEMFILE` environment variable; and
- That Gemfile is not an absolute path (e.g. `BUNDLE_GEMFILE=Gemfile`)
### Was was your diagnosis of the problem?
My diagnosis was that in `Bundler::SharedHelpers#default_gemfile`, the `Pathname` object being instantiated was not being expanded. So, in the case that `ENV["BUNDLE_GEMFILE"]` was not an absolute path, `Bundle.setup` would error out `Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)` since `Bundler.default_lockfile` derived itself from `Bundler.default_gemfile`.
### What is your fix for the problem, implemented in this PR?
My fix was to add `expand_path` to the `Pathname` object being returned in `Bundler::SharedHelpers#default_gemfile`
### Why did you choose this fix out of the possible options?
I chose this fix because Bundler was already deriving `Bundler::Sharedhelpers#root` with an `#expand_path`, so I wanted to follow that pattern.
-rw-r--r-- | lib/bundler/shared_helpers.rb | 2 | ||||
-rw-r--r-- | spec/bundler/shared_helpers_spec.rb | 12 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 54 |
3 files changed, 54 insertions, 14 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 07880387f0..01433a2096 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -28,7 +28,7 @@ module Bundler def default_gemfile gemfile = find_gemfile(:order_matters) raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).untaint + Pathname.new(gemfile).untaint.expand_path end def default_lockfile diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index 8586079974..c17f3b8582 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -30,6 +30,16 @@ RSpec.describe Bundler::SharedHelpers do ) end end + + context "Gemfile is not an absolute path" do + before { ENV["BUNDLE_GEMFILE"] = "Gemfile" } + + let(:expected_gemfile_path) { Pathname.new("Gemfile").expand_path } + + it "returns the Gemfile path" do + expect(subject.default_gemfile).to eq(expected_gemfile_path) + end + end end describe "#default_lockfile" do @@ -101,7 +111,7 @@ RSpec.describe Bundler::SharedHelpers do context "currently in directory with a Gemfile" do before { File.new("Gemfile", "w") } - it "returns path of the bundle gemfile" do + it "returns path of the bundle Gemfile" do expect(subject.in_bundle?).to eq("#{bundled_app}/Gemfile") end end diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 909378ab02..34caceba5a 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -269,21 +269,51 @@ RSpec.describe "Bundler.setup" do expect(bundled_app("Gemfile.lock")).to exist end - it "uses BUNDLE_GEMFILE to locate the gemfile if present" do - gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G + describe "$BUNDLE_GEMFILE" do + context "user provides an absolute path" do + it "uses BUNDLE_GEMFILE to locate the gemfile if present" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G - gemfile bundled_app("4realz"), <<-G - source "file://#{gem_repo1}" - gem "activesupport", "2.3.5" - G + gemfile bundled_app("4realz"), <<-G + source "file://#{gem_repo1}" + gem "activesupport", "2.3.5" + G + + ENV["BUNDLE_GEMFILE"] = bundled_app("4realz").to_s + bundle :install + + expect(the_bundle).to include_gems "activesupport 2.3.5" + end + end + + context "an absolute path is not provided" do + it "uses BUNDLE_GEMFILE to locate the gemfile if present" do + gemfile <<-G + source "file://#{gem_repo1}" + G - ENV["BUNDLE_GEMFILE"] = bundled_app("4realz").to_s - bundle :install + bundle "install" + bundle "install --deployment" - expect(the_bundle).to include_gems "activesupport 2.3.5" + ENV["BUNDLE_GEMFILE"] = "Gemfile" + ruby <<-R + require 'rubygems' + require 'bundler' + + begin + Bundler.setup + puts "WIN" + rescue ArgumentError => e + puts "FAIL" + end + R + + expect(out).to eq("WIN") + end + end end it "prioritizes gems in BUNDLE_PATH over gems in GEM_HOME" do |