Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Add check for BUNDLE_GEMFILE in cli #6331

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ def initialize(*args)
super

custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
if custom_gemfile && !custom_gemfile.empty?

if custom_gemfile && !custom_gemfile.empty? && !ENV["BUNDLE_GEMFILE"]
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", File.expand_path(custom_gemfile)
Bundler.reset_paths!
end

Bundler.reset_paths!

Bundler.settings.set_command_option_if_given :retry, options[:retry]

current_cmd = args.last[:current_command].name
Expand Down
45 changes: 40 additions & 5 deletions spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,51 @@
end
end

context "when ENV['BUNDLE_GEMFILE'] is set to an empty string" do
it "ignores it" do
gemfile bundled_app("Gemfile"), <<-G
context "behaviour with ENV['BUNDLE_GEMFILE']" do
before do
gemfile bundled_app("Gemfile.dev"), <<-G
source "file://#{gem_repo1}"
gem 'rack'
G

bundle :install, :env => { "BUNDLE_GEMFILE" => "" }
bundle! "config --local gemfile #{bundled_app("Gemfile.dev")}"
end

context "when not specified" do
it "uses the value specified in config file" do
bundle :install
bundle :list

expect(out).to include "rack (1.0.0)"
end
end

context "when set to an empty string" do
it "ignores it and searches for default gemfiles" do
gemfile bundled_app("Gemfile"), <<-G
source "file://#{gem_repo1}"
gem 'rack'
G

expect(the_bundle).to include_gems "rack 1.0.0"
bundle :install, :env => { "BUNDLE_GEMFILE" => "" }

expect(the_bundle).to include_gems "rack 1.0.0"
end
end

context "when passed a value" do
it "uses specified gemfile" do
with_env_vars("BUNDLE_GEMFILE" => "Gemfile.other") do
gemfile bundled_app("Gemfile.other"), <<-G
source "file://#{gem_repo1}"
gem 'rack'
G

bundle :install

expect(the_bundle).to include_gems "rack 1.0.0"
end
end
end
end

Expand Down