From 14e104e7075a56ed6377314ceaf34bd96baa7e49 Mon Sep 17 00:00:00 2001 From: Stephen Prater Date: Thu, 3 Sep 2015 01:43:12 -0700 Subject: [PATCH] Enable pry-like stop on binding.pry --- lib/byebug/processors/pry_processor.rb | 10 +++++++++- lib/pry-byebug/base.rb | 10 ++++++++++ lib/pry-byebug/pry_ext.rb | 1 + test/base_test.rb | 22 ++++++++++++++++++++++ test/examples/last_line.rb | 2 ++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/examples/last_line.rb diff --git a/lib/byebug/processors/pry_processor.rb b/lib/byebug/processors/pry_processor.rb index da2170e..a6d37e6 100644 --- a/lib/byebug/processors/pry_processor.rb +++ b/lib/byebug/processors/pry_processor.rb @@ -15,7 +15,11 @@ def self.start Byebug.start Setting[:autolist] = false Context.processor = self - Byebug.current_context.step_out(3, true) + if PryByebug.binding_behavior == :pry + Byebug.current_context.step_out(0, true) + else + Byebug.current_context.step_out(3, true) + end end # @@ -90,6 +94,10 @@ def n_hits(breakpoint) # Resume an existing Pry REPL at the paused point. # def resume_pry + if PryByebug.binding_behavior == :pry + Byebug::UpCommand.new(self, "up 3").execute + end + new_binding = frame._binding run do diff --git a/lib/pry-byebug/base.rb b/lib/pry-byebug/base.rb index 0a018be..82aa3d1 100644 --- a/lib/pry-byebug/base.rb +++ b/lib/pry-byebug/base.rb @@ -22,4 +22,14 @@ def check_file_context(target, e = nil) # Reference to currently running pry-remote server. Used by the processor. attr_accessor :current_remote_server + + def binding_behavior + @binding_behavior ||= :byebug + end + module_function :binding_behavior + + def binding_behavior=(style) + @binding_behavior = style + end + module_function :binding_behavior= end diff --git a/lib/pry-byebug/pry_ext.rb b/lib/pry-byebug/pry_ext.rb index 9dd98a6..f4658a2 100644 --- a/lib/pry-byebug/pry_ext.rb +++ b/lib/pry-byebug/pry_ext.rb @@ -4,6 +4,7 @@ class << Pry alias_method :start_without_pry_byebug, :start def start_with_pry_byebug(target = TOPLEVEL_BINDING, options = {}) + Pry.initial_session_setup if target.is_a?(Binding) && PryByebug.file_context?(target) Byebug::PryProcessor.start else diff --git a/test/base_test.rb b/test/base_test.rb index 41cef94..9bf38f4 100644 --- a/test/base_test.rb +++ b/test/base_test.rb @@ -16,3 +16,25 @@ def test_other_file_context end end end + +# +# Tests binding.pry stops at that line with PryByebug.break_behavior = :pry +# + +class TestStopsOnBinding < MiniTest::Spec + def setup + super + PryByebug.binding_behavior = :pry + @output = StringIO.new + @input = InputTester.new('') + redirect_pry_io(@input, @output) { load test_file('last_line') } + end + + def test_stops_on_binding + assert_match(/\=> \s*2:/, @output.string) + end + + def teardown + PryByebug.binding_behavior = :byebug + end +end diff --git a/test/examples/last_line.rb b/test/examples/last_line.rb new file mode 100644 index 0000000..97c254c --- /dev/null +++ b/test/examples/last_line.rb @@ -0,0 +1,2 @@ +require 'pry' +binding.pry