Don't load/save history or load rc if we can't find home.

Fixes: #477.
Signed-off-by: Jordon Bedwell <jordon@envygeeks.com>
This commit is contained in:
Jordon Bedwell 2012-02-15 05:24:03 -06:00
parent 4e8a436460
commit 3f9741b628
2 changed files with 18 additions and 1 deletions

View File

@ -249,7 +249,13 @@ class Pry
config.history ||= OpenStruct.new
config.history.should_save = true
config.history.should_load = true
config.history.file = File.expand_path("~/.pry_history")
config.history.file = File.expand_path("~/.pry_history") rescue nil
if config.history.file.nil?
config.should_load_rc = false
config.history.should_save = false
config.history.should_load = false
end
config.control_d_handler = DEFAULT_CONTROL_D_HANDLER

View File

@ -296,6 +296,17 @@ describe Pry do
Object.remove_const(:TEST_RC)
end
it "should not load the pryrc if it cannot expand ENV[HOME]" do
old_home = ENV['HOME']
old_rc = Pry.config.should_load_rc
ENV['HOME'] = nil
Pry.config.should_load_rc = true
lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) }.should.not.raise
ENV['HOME'] = old_home
Pry.config.should_load_rc = old_rc
end
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
Pry.config.should_load_rc = false
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)