summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2014-04-30 15:54:42 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2014-04-30 15:54:42 -0700
commit561b564d28e12731434513f1783cd519690e144b (patch)
treed78ec643c0c43002a852670e571f6eb38c94b463
parent56d6725b9fd1133d3a953b55096460fb4b219679 (diff)
parent3b77fffe9be2ba02c83dd4598d7072a3821918e3 (diff)
downloadchef-561b564d28e12731434513f1783cd519690e144b.tar.gz
Merge pull request #1398 from opscode/config-env
collect :user_home at correct time, for windows
-rw-r--r--.travis.yml2
-rw-r--r--lib/chef/config.rb15
-rw-r--r--spec/unit/config_spec.rb17
3 files changed, 16 insertions, 18 deletions
diff --git a/.travis.yml b/.travis.yml
index 7d6c61fcbc..c60be3843b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,7 +13,7 @@ before_install:
matrix:
include:
- - rvm: 1.8.7
+ - rvm: 1.8.7-p374
- rvm: 1.9.3
- rvm: 2.0.0
- rvm: 2.1.0
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index f6724354d5..a836c62456 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -85,7 +85,7 @@ class Chef
def self.platform_specific_path(path)
if on_windows?
# turns /etc/chef/client.rb into C:/chef/client.rb
- system_drive = ENV['SYSTEMDRIVE'] ? ENV['SYSTEMDRIVE'] : ""
+ system_drive = env['SYSTEMDRIVE'] ? env['SYSTEMDRIVE'] : ""
path = File.join(system_drive, path.split('/')[2..-1])
# ensure all forward slashes are backslashes
path.gsub!(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
@@ -520,9 +520,18 @@ class Chef
set_defaults_for_nix
end
+ # This provides a hook which rspec can stub so that we can avoid twiddling
+ # global state in tests.
+ def self.env
+ ENV
+ end
+
+ def self.windows_home_path
+ windows_home_path = env['SYSTEMDRIVE'] + env['HOMEPATH'] if env['SYSTEMDRIVE'] && env['HOMEPATH']
+ end
+
# returns a platform specific path to the user home dir
- windows_home_path = ENV['SYSTEMDRIVE'] + ENV['HOMEPATH'] if ENV['SYSTEMDRIVE'] && ENV['HOMEPATH']
- default( :user_home ) { ENV['HOME'] || windows_home_path || ENV['USERPROFILE'] }
+ default( :user_home ) { env['HOME'] || windows_home_path || env['USERPROFILE'] }
# Enable file permission fixup for selinux. Fixup will be done
# only if selinux is enabled in the system.
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index 8f41845644..82506f556c 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -21,10 +21,6 @@ require 'spec_helper'
require 'chef/exceptions'
describe Chef::Config do
- before(:all) do
- @original_env = { 'HOME' => ENV['HOME'], 'SYSTEMDRIVE' => ENV['SYSTEMDRIVE'], 'HOMEPATH' => ENV['HOMEPATH'], 'USERPROFILE' => ENV['USERPROFILE'] }
- end
-
describe "config attribute writer: chef_server_url" do
before do
Chef::Config.chef_server_url = "https://junglist.gen.nz"
@@ -132,7 +128,7 @@ describe Chef::Config do
it "should return a windows path on windows systems" do
platform_mock :windows do
path = "/etc/chef/cookbooks"
- ENV.stub(:[]).with('SYSTEMDRIVE').and_return('C:')
+ Chef::Config.stub(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
# match on a regex that looks for the base path with an optional
# system drive at the beginning (c:)
# system drive is not hardcoded b/c it can change and b/c it is not present on linux systems
@@ -283,21 +279,14 @@ describe Chef::Config do
describe "Chef::Config[:user_home]" do
it "should set when HOME is provided" do
- ENV['HOME'] = "/home/kitten"
+ Chef::Config.stub(:env).and_return({ 'HOME' => "/home/kitten" })
Chef::Config[:user_home].should == "/home/kitten"
end
it "should be set when only USERPROFILE is provided" do
- ENV['HOME'], ENV['SYSTEMDRIVE'], ENV['HOMEPATH'] = nil, nil, nil
- ENV['USERPROFILE'] = "/users/kitten"
+ Chef::Config.stub(:env).and_return({ 'USERPROFILE' => "/users/kitten" })
Chef::Config[:user_home].should == "/users/kitten"
end
-
- after(:each) do
- @original_env.each do |env_setting|
- ENV[env_setting[0]] = env_setting[1]
- end
- end
end
describe "Chef::Config[:encrypted_data_bag_secret]" do