summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Perez <adrianperez.deb@gmail.com>2015-11-17 21:18:24 +0100
committerAdrian Perez <adrianperez.deb@gmail.com>2015-11-17 21:19:20 +0100
commit54c4bc32e54cda815809bb0c6da5ce73a5eb9ca3 (patch)
tree1267e2548a9188bfc7570175e2c201d4ee7fc344
parentad922ae3c3f35fdd838b3f61718f994c9d1a110e (diff)
downloadbundler-54c4bc32e54cda815809bb0c6da5ce73a5eb9ca3.tar.gz
Check SILENCE_ROOT_WARNING env to skip warning on root install cmds
-rw-r--r--lib/bundler/cli/install.rb2
-rw-r--r--spec/install/gems/sudo_spec.rb16
-rw-r--r--spec/support/helpers.rb5
3 files changed, 19 insertions, 4 deletions
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index 1f5337d46e..2f34ab2fce 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -8,7 +8,7 @@ module Bundler
def run
Bundler.ui.level = "error" if options[:quiet]
- warn_if_root
+ warn_if_root unless ENV['SILENCE_ROOT_WARNING']
[:with, :without].each do |option|
if options[option]
diff --git a/spec/install/gems/sudo_spec.rb b/spec/install/gems/sudo_spec.rb
index 640572ed6d..12a4ef90df 100644
--- a/spec/install/gems/sudo_spec.rb
+++ b/spec/install/gems/sudo_spec.rb
@@ -143,10 +143,22 @@ describe "when using sudo", :sudo => true do
end
describe "and root runs install" do
- it "warns against that" do
+ let(:warning) { "Don't run Bundler as root." }
+
+ before do
gemfile %|source "file://#{gem_repo1}"|
+ end
+
+ it "warns against that" do
bundle :install, :sudo => true
- expect(out).to include("Don't run Bundler as root.")
+ expect(out).to include(warning)
+ end
+
+ context "when ENV['SILENCE_ROOT_WARNING'] is set" do
+ it 'skips the warning' do
+ bundle :install, sudo: :preserve_env, :env => { 'SILENCE_ROOT_WARNING' => true}
+ expect(out).to_not include(warning)
+ end
end
end
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 49d0d6f133..c325bb0e04 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -64,7 +64,10 @@ module Spec
def bundle(cmd, options = {})
expect_err = options.delete(:expect_err)
- sudo = "sudo" if options.delete(:sudo)
+ with_sudo = options.delete(:sudo)
+ if with_sudo
+ sudo = with_sudo == :preserve_env ? 'sudo -E' : 'sudo'
+ end
options["no-color"] = true unless options.key?("no-color") || %w(exec conf).include?(cmd.to_s[0..3])
bundle_bin = File.expand_path("../../../exe/bundle", __FILE__)