1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Unwrap last exception when setting _ex_

This commit is contained in:
Ryan Fitzgerald 2014-03-09 19:39:01 -07:00
parent 0ae0d8d1e4
commit 67806cff46
5 changed files with 39 additions and 8 deletions

View file

@ -98,6 +98,10 @@ class Pry
mri? && RUBY_VERSION =~ /2.0/
end
def mri_21?
mri? && RUBY_VERSION =~ /2.1/
end
# Send the given text through the best available pager (if Pry.pager is
# enabled). Infers where to send the output if used as a mixin.
def stagger_output(text, out = nil)

View file

@ -1,3 +1,5 @@
# LastException is a proxy used to add functionality to the `last_exception`
# attribute of Pry instances.
class Pry::LastException < BasicObject
attr_reader :file, :line
attr_accessor :bt_index
@ -16,12 +18,12 @@ class Pry::LastException < BasicObject
end
end
def respond_to_missing?(name, boolean=false)
def respond_to_missing?(name, include_private = false)
@e.respond_to?(name)
end
def pry?
true
def wrapped_exception
@e
end
def bt_source_location_for(index)

View file

@ -183,7 +183,7 @@ class Pry
{ _in_: input_array,
_out_: output_array,
_pry_: self,
_ex_: last_exception,
_ex_: last_exception && last_exception.wrapped_exception,
_file_: last_file,
_dir_: last_dir,
_: proc { last_result },

View file

@ -75,7 +75,7 @@ describe Pry do
it "returns an instance of Pry::LastException" do
@pry.last_exception = @e
should.satisfy { @pry.last_exception.pry? == true }
@pry.last_exception.wrapped_exception.should == @e
end
it "returns a frozen exception" do

View file

@ -21,9 +21,34 @@ describe "Sticky locals (_file_ and friends)" do
end
end
# Using mock_pry here until we figure out exception handling
it 'locals should keep value after cd-ing (_ex_)' do
mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
describe '_ex_' do
it 'returns the last exception without wrapping it in a LastException' do
ReplTester.start do
input 'raise "halp"'
input '_ex_.message == "halp"'
output '=> true'
if Pry::Helpers::BaseHelpers.mri_20? || Pry::Helpers::BaseHelpers.mri_21?
input 'Kernel.instance_method(:class).bind(_ex_).call'
output '=> RuntimeError'
end
input '_ex_.wrapped_exception'
output /NoMethodError/
end
end
it 'keeps its value after cd-ing' do
ReplTester.start do
input 'error blah'
input '$x = _ex_'
input 'cd 0'
input '_ex_ == $x'
output '=> true'
end
end
end
it 'locals should keep value after cd-ing (_file_ and _dir_)' do