Skip to content

Commit

Permalink
Expand Windows home candidates. RF #28371
Browse files Browse the repository at this point in the history
  • Loading branch information
luislavena committed Jul 10, 2010
1 parent d5871f5 commit 147872f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-

2010-07-10 Luis Lavena <luislavena@gmail.com>

* lib/rubygems.rb: Expand Windows user home canditates for Ruby 1.8
Bug #28371

2010-05-13 Eric Hodel <drbrain@segment7.net>

* lib/rubygems.rb: 1.3.7.
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems.rb
Expand Up @@ -499,11 +499,11 @@ def self.find_files(path)
def self.find_home
unless RUBY_VERSION > '1.9' then
['HOME', 'USERPROFILE'].each do |homekey|
return ENV[homekey] if ENV[homekey]
return File.expand_path(ENV[homekey]) if ENV[homekey]
end

if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
return File.expand_path("#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}")
end
end

Expand Down
33 changes: 27 additions & 6 deletions test/test_gem.rb
Expand Up @@ -597,27 +597,48 @@ def test_self_user_home
end
end

def test_self_user_home_userprofile
skip 'Ruby 1.9 properly handles ~ path expansion' if RUBY_VERSION > '1.9'

Gem.clear_paths

# safe-keep env variables
orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']

# prepare for the test
ENV.delete('HOME')
ENV['USERPROFILE'] = "W:\\Users\\RubyUser"

assert_equal 'W:/Users/RubyUser', Gem.user_home

ensure
ENV['HOME'] = orig_home
ENV['USERPROFILE'] = orig_user_profile
end

def test_self_user_home_user_drive_and_path
skip 'Ruby 1.9 properly handles ~ path expansion' if RUBY_VERSION > '1.9'

Gem.clear_paths

# safe-keep env variables
orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
orig_user_drive, orig_user_path = ENV['HOMEDRIVE'], ENV['HOMEPATH']
orig_home_drive, orig_home_path = ENV['HOMEDRIVE'], ENV['HOMEPATH']

# prepare the environment
ENV.delete('HOME')
ENV.delete('USERPROFILE')
ENV['HOMEDRIVE'] = 'Z:'
ENV['HOMEPATH'] = '\\Users\\RubyUser'
ENV['HOMEPATH'] = "\\Users\\RubyUser"

assert_equal "Z:\\Users\\RubyUser", Gem.user_home
assert_equal 'Z:/Users/RubyUser', Gem.user_home

ensure
ENV['HOME'] = orig_home
ENV['USERPROFILE'] = orig_user_profile
ENV['USERDRIVE'] = orig_user_drive
ENV['USERPATH'] = orig_user_path
end if '1.9' > RUBY_VERSION
ENV['HOMEDRIVE'] = orig_home_drive
ENV['HOMEPATH'] = orig_home_path
end

def test_load_plugins
with_plugin('load') { Gem.load_plugins }
Expand Down

0 comments on commit 147872f

Please sign in to comment.