Skip to content

Commit

Permalink
Enable pry-like stop on binding.pry
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenprater committed Sep 3, 2015
1 parent e4b57ac commit 4e24253
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/byebug/processors/pry_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/pry-byebug/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/examples/last_line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'pry'
binding.pry

0 comments on commit 4e24253

Please sign in to comment.