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'" }