From f649e283ae0a63e55eba1f592639c2db80af36ca Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 15 Jan 2013 20:06:44 +0100 Subject: [PATCH] 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) --- lib/pry/commands/edit.rb | 6 +++++- spec/commands/edit_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb index 05f66c71..ea74207c 100644 --- a/lib/pry/commands/edit.rb +++ b/lib/pry/commands/edit.rb @@ -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 diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index c3d5d6b3..761ea1b2 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -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'" }