diff options
author | Adrian Perez <adrianperez.deb@gmail.com> | 2015-11-18 16:58:56 +0100 |
---|---|---|
committer | Adrian Perez <adrianperez.deb@gmail.com> | 2015-11-18 16:58:56 +0100 |
commit | b00e4daa160e2ea74d741bb60511bae07f4b8aad (patch) | |
tree | 049f76735cfd9f1cf86f3cc8cf692711a787c507 | |
parent | 54c4bc32e54cda815809bb0c6da5ce73a5eb9ca3 (diff) | |
download | bundler-b00e4daa160e2ea74d741bb60511bae07f4b8aad.tar.gz |
Promote silence_root_warning to Bundler.settings option, fix style issues
-rw-r--r-- | lib/bundler/cli/install.rb | 4 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 2 | ||||
-rw-r--r-- | spec/install/gems/sudo_spec.rb | 20 | ||||
-rw-r--r-- | spec/support/helpers.rb | 5 |
4 files changed, 22 insertions, 9 deletions
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 2f34ab2fce..256ae0a7d2 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 unless ENV['SILENCE_ROOT_WARNING'] + warn_if_root [:with, :without].each do |option| if options[option] @@ -157,7 +157,7 @@ module Bundler private def warn_if_root - return if Bundler::WINDOWS || !Process.uid.zero? + return if Bundler.settings[:silence_root_warning] || Bundler::WINDOWS || !Process.uid.zero? Bundler.ui.warn "Don't run Bundler as root. Bundler can ask for sudo " \ "if it is needed, and installing your bundle as root will break this " \ "application for all non-root users on this machine.", :wrap => true diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index f5286c9a22..c859a7677b 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -2,7 +2,7 @@ require "uri" module Bundler class Settings - BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc).freeze + BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc silence_root_warning).freeze NUMBER_KEYS = %w(retry timeout redirect ssl_verify_mode).freeze DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 } diff --git a/spec/install/gems/sudo_spec.rb b/spec/install/gems/sudo_spec.rb index 12a4ef90df..ed5ac405e0 100644 --- a/spec/install/gems/sudo_spec.rb +++ b/spec/install/gems/sudo_spec.rb @@ -154,11 +154,25 @@ describe "when using sudo", :sudo => true do 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} + context "when ENV['BUNDLE_SILENCE_ROOT_WARNING'] is set" do + it "skips the warning" do + bundle :install, :sudo => :preserve_env, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => true } expect(out).to_not include(warning) end end + + context "when silence_root_warning is passed as an option" do + it "skips the warning" do + bundle :install, :sudo => true, :silence_root_warning => true + expect(out).to_not include(warning) + end + end + + context "when silence_root_warning = false" do + it "warns against that" do + bundle :install, :sudo => true, :silence_root_warning => false + expect(out).to include(warning) + end + end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index c325bb0e04..ae6df9e76d 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -65,9 +65,8 @@ module Spec def bundle(cmd, options = {}) expect_err = options.delete(:expect_err) with_sudo = options.delete(:sudo) - if with_sudo - sudo = with_sudo == :preserve_env ? 'sudo -E' : 'sudo' - end + sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo + 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__) |