-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36eff10
commit 63a78b8
Showing
5 changed files
with
153 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in pry-nav.gemspec | ||
gemspec | ||
|
||
gem "test-unit" | ||
|
||
gem "pry", "~> 0.14.1" | ||
gem "pry-remote" |
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
#!/usr/bin/env rake | ||
require 'bundler/gem_tasks' | ||
require 'rake/testtask' | ||
|
||
task :default => :test | ||
|
||
Rake::TestTask.new(:test) do |task| | ||
task.libs << 'test' | ||
task.test_files = FileList['test/*_test.rb'] | ||
task.verbose = true | ||
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,98 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("test_helper", __dir__) | ||
|
||
class PryNavTest < Test::Unit::TestCase | ||
# removing color makes string matching easier | ||
def setup | ||
Pry.color = false | ||
end | ||
|
||
# lifted from: | ||
# https://github.com/pry/pry-stack_explorer/blob/e3e6bd202e092712900f0d5f239ee21ab2f32b2b/test/support/io_utils.rb | ||
def with_pry_output_captured(new_in, new_out = StringIO.new) | ||
old_in = Pry.input | ||
old_out = Pry.output | ||
|
||
# direct stdout so we can test against `puts` in the method we defined above | ||
old_stdout = $stdout | ||
$stdout = new_out | ||
|
||
Pry.input = new_in | ||
Pry.output = new_out | ||
|
||
begin | ||
yield | ||
ensure | ||
Pry.input = old_in | ||
Pry.output = old_out | ||
$stdout = old_stdout | ||
end | ||
|
||
new_out | ||
end | ||
|
||
# `step` will step into the frames, while `next` keeps the debugging execution within the frame | ||
def test_step | ||
o = NavSample.new | ||
|
||
r = with_pry_output_captured( | ||
InputTester.new( | ||
"step", | ||
|
||
"step", | ||
"step", | ||
|
||
"continue" | ||
) | ||
){ o.nested_bind_with_call } | ||
|
||
# initial binding display | ||
assert(r.string.include?("def nested_bind_with_call")) | ||
|
||
# after two steps, we are in the second frame, let's make sure we get there | ||
assert(r.string.include?("def nested_bind_call")) | ||
|
||
assert(/nested_puts\n/ =~ r.string) | ||
assert(/root_puts\n/ =~ r.string) | ||
end | ||
|
||
def test_next | ||
o = NavSample.new | ||
|
||
r = with_pry_output_captured( | ||
InputTester.new( | ||
"next", | ||
"next", | ||
"next", | ||
"continue" | ||
) | ||
){ o.nested_bind_with_call } | ||
|
||
assert(r.string.include?("def nested_bind_with_call")) | ||
refute(r.string.include?("def nested_bind_call")) | ||
|
||
assert(/nested_puts\n/ =~ r.string) | ||
assert(/root_puts\n/ =~ r.string) | ||
end | ||
|
||
def test_continue | ||
o = NavSample.new | ||
|
||
r = with_pry_output_captured( | ||
InputTester.new( | ||
"continue", | ||
) | ||
){ o.nested_bind_with_call } | ||
|
||
assert(r.string.include?("def nested_bind_with_call")) | ||
refute(r.string.include?("def nested_bind_call")) | ||
|
||
assert(/nested_puts\n/ =~ r.string) | ||
assert(/root_puts\n/ =~ r.string) | ||
end | ||
|
||
def test_file_context | ||
assert(PryNav.check_file_context(binding)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'bundler/setup' | ||
require 'test/unit' | ||
|
||
# lets make sure it works will all of the pry extensions | ||
Bundler.require | ||
|
||
class NavSample | ||
def nested_bind_with_call | ||
Pry.start(binding) | ||
nested_bind_call | ||
puts "root_puts" | ||
end | ||
|
||
def nested_bind_call | ||
puts "nested_puts" | ||
end | ||
end | ||
|
||
# lifted from: | ||
# https://github.com/pry/pry-stack_explorer/blob/e3e6bd202e092712900f0d5f239ee21ab2f32b2b/test/support/input_tester.rb | ||
|
||
class InputTester | ||
def initialize(*actions) | ||
if actions.last.is_a?(Hash) && actions.last.keys == [:history] | ||
@hist = actions.pop[:history] | ||
end | ||
|
||
@orig_actions = actions.dup | ||
@actions = actions | ||
end | ||
|
||
def readline(*) | ||
@actions.shift.tap{ |line| @hist << line if @hist } | ||
end | ||
|
||
def rewind | ||
@actions = @orig_actions.dup | ||
end | ||
end |