Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated show-stack and added tests

  • Loading branch information...
commit ff25722082c32d0750fac5cf64a86f7e881e44f5 1 parent eefc7aa
@banister banister authored
View
9 lib/pry-stack_explorer.rb
@@ -22,6 +22,15 @@ def self.create_and_push_frame_manager(bindings, _pry_)
Thread.current[:__pry_frame_managers__][_pry_].push FrameManager.new(bindings, _pry_)
end
+ # Return the complete frame manager stack for the Pry instance
+ # @param [Pry] _pry_ The Pry instance associated with the frame
+ # managers
+ # @return [Array] The stack of Pry::FrameManager objections
+ def self.all_frame_managers(_pry_)
+ init_frame_hash
+ Thread.current[:__pry_frame_managers__][_pry_]
+ end
+
# Delete the currently active frame manager
# @param [Pry] _pry_ The Pry instance associated with the frame managers
def self.pop_frame_manager(_pry_)
View
15 lib/pry-stack_explorer/commands.rb
@@ -1,3 +1,5 @@
+require 'pry'
+
module PryStackExplorer
StackCommands = Pry::CommandSet.new do
command "up", "Go up to the caller's context. Accepts optional numeric parameter for how many frames to move up." do |inc_str|
@@ -77,15 +79,14 @@ def frame_info(b, verbose = false)
b_self = b.eval('self')
meth_obj = Pry::Method.new(b_self.method(meth)) if meth
- type = b.frame_type ? "(#{b.frame_type})" : ""
- desc = b.frame_description ? "#{text.bold('Description:')} #{b.frame_description}".ljust(60) :
- "#{text.bold('Description:')} #{PryStackExplorer.frame_manager(_pry_).frame_info_for(b)}".ljust(60)
- sig = meth ? "#{text.bold('Signature:')} #{se_signature_with_owner(meth_obj)}".ljust(40) : "".ljust(32)
+ type = b.frame_type ? "[#{b.frame_type}]" : ""
+ desc = b.frame_description ? "#{b.frame_description} in " : "#{PryStackExplorer.frame_manager(_pry_).frame_info_for(b)} in "
+ sig = meth ? "#{se_signature_with_owner(meth_obj)}" : ""
- slf_class = "#{text.bold('Self.class:')} #{b_self.class}".ljust(40)
- path = "#{text.bold("@ File:")} #{b.eval('__FILE__')}:#{b.eval('__LINE__')}"
+ slf_class = "#{Pry.view_clip(b_self)}"
+ path = "@ #{b.eval('__FILE__')}:#{b.eval('__LINE__')}"
- "#{desc} #{slf_class} #{sig} #{type} #{path if verbose}"
+ "#{desc} #{slf_class} #{sig} #{path if verbose} #{type}"
end
def se_signature_with_owner(meth_obj)
View
25 test/test.rb → test/helper.rb 100755 → 100644
@@ -1,12 +1,13 @@
-direc = File.dirname(__FILE__)
-
-require 'rubygems'
-require "#{direc}/../lib/pry-stack_explorer"
-require 'bacon'
-
-puts "Testing pry-stack_explorer version #{PryStackExplorer::VERSION}..."
-puts "Ruby version: #{RUBY_VERSION}"
-
-describe PryStackExplorer do
-end
-
+require 'rubygems'
+
+unless Object.const_defined? 'PryStackExplorer'
+ $:.unshift File.expand_path '../../lib', __FILE__
+ require 'pry-stack_explorer'
+end
+
+require 'bacon'
+
+puts "Testing pry-stack_explorer version #{PryStackExplorer::VERSION}..."
+puts "Ruby version: #{RUBY_VERSION}"
+
+PE = PryStackExplorer
View
39 test/test_stack_explorer.rb
@@ -0,0 +1,39 @@
+require 'helper'
+
+describe PryStackExplorer do
+
+ before do
+ @pry_instance = Pry.new
+ @bindings = [binding, binding]
+ end
+
+ after do
+ PE.clear_frame_managers(@pry_instance)
+ end
+
+ it "should create and push one new FrameManager" do
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
+ PE.frame_manager(@pry_instance).is_a?(PE::FrameManager).should == true
+ PE.all_frame_managers(@pry_instance).count.should == 1
+ end
+
+ it "should have the correct bindings" do
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
+ PE.frame_manager(@pry_instance).bindings.should == @bindings
+ end
+
+ it "should pop a FrameManager" do
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
+ PE.pop_frame_manager(@pry_instance)
+ PE.all_frame_managers(@pry_instance).count.should == 1
+ end
+
+ it "should clear all FrameManagers for a Pry instance" do
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
+ PE.clear_frame_managers(@pry_instance)
+ PE.all_frame_managers(@pry_instance).count.should == 0
+ end
+end
+
View
13 tester.rb
@@ -10,7 +10,18 @@ def b
def c
u = 50
- 5.pry
+ binding.pry
+ puts "hi"
+ puts "bye"
+ v = 20
+ puts v
+ k
+end
+
+def k
+ puts "lovely girl"
+ james = "hello"
+ puts james
end
a
Please sign in to comment.
Something went wrong with that request. Please try again.