Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pry-like stop on binding.pry #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions lib/pry-byebug/pry_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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