summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schmidt <ts@soundcloud.com>2013-04-18 03:13:52 +0200
committerTobias Schmidt <ts@soundcloud.com>2013-04-18 03:21:26 +0200
commit3149427abc3036806e5169bdc2b5a9ca57ba3664 (patch)
treea695255ae69cd6f7cdeeacdcc43b7c6de88c5858
parent9f4f888415b0dffb906d99a71b084b4fcfb61ce0 (diff)
downloadnet-ssh-3149427abc3036806e5169bdc2b5a9ca57ba3664.tar.gz
Make sure HOME is an absolute path
In setups where $HOME is not set, the previous implementation set "." as default. The problem is that File.expand_path will raise ArgumentError "non-absolute home" if HOME is a relative path. This change makes sure HOME is an absolute path.
-rw-r--r--README.rdoc2
-rw-r--r--lib/net/ssh.rb2
-rw-r--r--test/test_config.rb5
3 files changed, 7 insertions, 2 deletions
diff --git a/README.rdoc b/README.rdoc
index fe4599f..35646c2 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -153,7 +153,7 @@ which should produce the following:
Run the test suite from the net-ssh directory with the following command:
- ruby -Ilib -Itest -rrubygems test/test_all.rb
+ bash -c 'unset HOME && ruby -Ilib -Itest -rrubygems test/test_all.rb'
Run a single test file like this:
diff --git a/lib/net/ssh.rb b/lib/net/ssh.rb
index 2fbe078..809e565 100644
--- a/lib/net/ssh.rb
+++ b/lib/net/ssh.rb
@@ -1,6 +1,6 @@
# Make sure HOME is set, regardless of OS, so that File.expand_path works
# as expected with tilde characters.
-ENV['HOME'] ||= ENV['HOMEPATH'] ? "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" : "."
+ENV['HOME'] ||= ENV['HOMEPATH'] ? "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" : Dir.pwd
require 'logger'
diff --git a/test/test_config.rb b/test/test_config.rb
index 548072f..634252a 100644
--- a/test/test_config.rb
+++ b/test/test_config.rb
@@ -1,7 +1,12 @@
require 'common'
require 'net/ssh/config'
+require 'pathname'
class TestConfig < Test::Unit::TestCase
+ def test_home_should_be_absolute_path
+ assert Pathname.new(ENV['HOME']).absolute?
+ end
+
def test_load_for_non_existant_file_should_return_empty_hash
bogus_file = File.expand_path("/bogus/file")
File.expects(:readable?).with(bogus_file).returns(false)