mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Be robust to errors in ~/.pryrc
This commit is contained in:
parent
7daa9773d8
commit
bd492b853c
3 changed files with 47 additions and 1 deletions
|
@ -58,7 +58,11 @@ class Pry
|
|||
def self.load_rc
|
||||
files = RC_FILES.collect { |file_name| File.expand_path(file_name) }.uniq
|
||||
files.each do |file_name|
|
||||
load(file_name) if File.exists?(file_name)
|
||||
begin
|
||||
load(file_name) if File.exists?(file_name)
|
||||
rescue RescuableException => e
|
||||
puts "Error loading #{file_name}: #{e}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -322,6 +322,46 @@ describe Pry do
|
|||
Object.const_defined?(:TEST_RC).should == false
|
||||
Pry.config.should_load_rc = false
|
||||
end
|
||||
|
||||
describe "that raise exceptions" do
|
||||
before do
|
||||
Pry::RC_FILES << File.expand_path("../testrcbad", __FILE__)
|
||||
Pry.config.should_load_rc = true
|
||||
|
||||
putsed = nil
|
||||
|
||||
# YUCK! horrible hack to get round the fact that output is not configured
|
||||
# at the point this message is printed.
|
||||
(class << Pry; self; end).send(:define_method, :puts) { |str|
|
||||
putsed = str
|
||||
}
|
||||
|
||||
@doing_it = lambda{
|
||||
Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => Pry::NullOutput)
|
||||
putsed
|
||||
}
|
||||
end
|
||||
|
||||
after do
|
||||
Object.remove_const(:TEST_BEFORE_RAISE)
|
||||
Object.remove_const(:TEST_AFTER_RAISE)
|
||||
(class << Pry; undef_method :puts; end)
|
||||
end
|
||||
|
||||
it "should not raise exceptions" do
|
||||
@doing_it.should.not.raise
|
||||
end
|
||||
|
||||
it "should continue to run pry" do
|
||||
@doing_it[]
|
||||
Object.const_defined?(:TEST_BEFORE_RAISE).should == true
|
||||
Object.const_defined?(:TEST_AFTER_RAISE).should == true
|
||||
end
|
||||
|
||||
it "should output an error" do
|
||||
@doing_it[].should =~ /Error loading #{File.expand_path("../testrcbad", __FILE__)}: messin with ya/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "nesting" do
|
||||
|
|
2
test/testrcbad
Normal file
2
test/testrcbad
Normal file
|
@ -0,0 +1,2 @@
|
|||
TEST_BEFORE_RAISE = 1
|
||||
raise "messin with ya"
|
Loading…
Reference in a new issue