-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from christian-schulze/add-frame-nav-commands-…
…up-and-down Add frame nav commands up, down and frame through byebug
- Loading branch information
Showing
10 changed files
with
236 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
# Main container module for Pry-Byebug functionality | ||
# | ||
module PryByebug | ||
VERSION = '3.0.1' | ||
VERSION = '3.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# | ||
# Main Pry class. | ||
# | ||
# We're going to add to it custom frame commands for Pry-Byebug | ||
# | ||
class Pry | ||
FrameCommands = CommandSet.new do | ||
create_command 'up' do | ||
description 'Move current frame up.' | ||
|
||
banner <<-BANNER | ||
Usage: up [TIMES] | ||
Move current frame up. By default, moves by 1 frame. | ||
Examples: | ||
up #=> Move up 1 frame. | ||
up 5 #=> Move up 5 frames. | ||
BANNER | ||
|
||
def process | ||
PryByebug.check_file_context(target) | ||
|
||
frame_navigation :up, times: args.first | ||
end | ||
end | ||
|
||
create_command 'down' do | ||
description 'Move current frame down.' | ||
|
||
banner <<-BANNER | ||
Usage: down [TIMES] | ||
Move current frame down. By default, moves by 1 frame. | ||
Examples: | ||
down #=> Move down 1 frame. | ||
down 5 #=> Move down 5 frames. | ||
BANNER | ||
|
||
def process | ||
PryByebug.check_file_context(target) | ||
|
||
frame_navigation :down, times: args.first | ||
end | ||
end | ||
|
||
create_command 'frame' do | ||
description 'Move to specified frame #.' | ||
|
||
banner <<-BANNER | ||
Usage: frame [TIMES] | ||
Move to specified frame #. | ||
Examples: | ||
frame #=> Show current frame #. | ||
frame 5 #=> Move to frame 5. | ||
BANNER | ||
|
||
def process | ||
PryByebug.check_file_context(target) | ||
|
||
frame_navigation :frame, index: args.first | ||
end | ||
end | ||
|
||
helpers do | ||
def frame_navigation(action, options = {}) | ||
_pry_.binding_stack.clear # Clear the binding stack. | ||
|
||
# Break out of the REPL loop and signal tracer | ||
throw :breakout_nav, action: action, options: options, pry: _pry_ | ||
end | ||
end | ||
end | ||
|
||
Pry.commands.import(FrameCommands) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Toy class for testing frame commands | ||
# | ||
class Frames | ||
def method_a | ||
method_b | ||
end | ||
|
||
def method_b | ||
binding.pry | ||
end | ||
end | ||
|
||
Frames.new.method_a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'test_helper' | ||
|
||
# | ||
# Tests for pry-byebug frame commands. | ||
# | ||
class FramesTest < MiniTest::Spec | ||
let(:output) { StringIO.new } | ||
|
||
before do | ||
Pry.color, Pry.pager, Pry.hooks = false, false, Pry::DEFAULT_HOOKS | ||
end | ||
|
||
describe 'Up command' do | ||
let(:input) { InputTester.new('up', 'down') } | ||
|
||
before do | ||
redirect_pry_io(input, output) { load test_file('frames') } | ||
end | ||
|
||
it 'shows current line' do | ||
output.string.must_match(/=> \s*6: \s*method_b/) | ||
end | ||
end | ||
|
||
describe 'Down command' do | ||
let(:input) { InputTester.new('up', 'down') } | ||
|
||
before do | ||
redirect_pry_io(input, output) { load test_file('frames') } | ||
end | ||
|
||
it 'shows current line' do | ||
output.string.must_match(/=> \s*11: \s*end/) | ||
end | ||
end | ||
|
||
describe 'Frame command' do | ||
before do | ||
redirect_pry_io(input, output) { load test_file('frames') } | ||
end | ||
|
||
describe 'jump to frame 1' do | ||
let(:input) { InputTester.new('frame 1', 'frame 0') } | ||
|
||
it 'shows current line' do | ||
output.string.must_match(/=> \s*6: \s*method_b/) | ||
end | ||
end | ||
|
||
describe 'jump to current frame' do | ||
let(:input) { InputTester.new('frame 0') } | ||
|
||
it 'shows current line' do | ||
output.string.must_match(/=> \s*11: \s*end/) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters