mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
edit: ensure 'edit --ex' always edits the exception
There was a bug where if 'edit --ex' was invoked in a patched method context it would instead to the equivalent of 'edit --method' (patching the current method rather than the exception)
This commit is contained in:
parent
08ac190bcb
commit
f649e283ae
2 changed files with 27 additions and 1 deletions
|
@ -69,8 +69,12 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def file_based_exception?
|
||||
opts.present?(:ex) && !opts.present?(:patch)
|
||||
end
|
||||
|
||||
def runtime_patch?
|
||||
opts.present?(:patch) || pry_method?(code_object)
|
||||
!file_based_exception? && (opts.present?(:patch) || pry_method?(code_object))
|
||||
end
|
||||
|
||||
def apply_runtime_patch
|
||||
|
|
|
@ -142,6 +142,7 @@ describe "edit" do
|
|||
def last_exception=(exception)
|
||||
@pry.last_exception = exception
|
||||
end
|
||||
def last_exception; @pry.last_exception; end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -177,6 +178,27 @@ describe "edit" do
|
|||
FOO.should == 'BAR'
|
||||
end
|
||||
|
||||
# regression test (this used to edit the current method instead
|
||||
# of the exception)
|
||||
it 'edits the exception even when in a patched method context' do
|
||||
source_location = nil
|
||||
Pry.config.editor = lambda {|file, line|
|
||||
source_location = [file, line]
|
||||
nil
|
||||
}
|
||||
|
||||
Pad.le = @t.last_exception
|
||||
redirect_pry_io(InputTester.new("def broken_method", "binding.pry", "end",
|
||||
"broken_method",
|
||||
"_pry_.last_exception = Pad.le",
|
||||
"edit --ex -n", "exit-all", "exit-all")) do
|
||||
Object.new.pry
|
||||
end
|
||||
|
||||
source_location.should == [@path, 3]
|
||||
Pad.clear
|
||||
end
|
||||
|
||||
it "should not reload the file if -n is passed" do
|
||||
Pry.config.editor = lambda {|file, line|
|
||||
File.open(file, 'w'){|f| f << "FOO2 = 'BAZ'" }
|
||||
|
|
Loading…
Reference in a new issue