pry-stack_explorer 0.2.8pre8 → 0.2.8pre9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,6 +5,10 @@ pry-stack_explorer
5
5
 
6
6
  _Walk the stack in a Pry session_
7
7
 
8
+ **Please note, pry-stack_explorer has not been officially released yet and the prerelease gem that is available is NOT compatible with the current Pry gem (0.9.7.4).
9
+ The prerelease gem only exists for testing purposes among Pry core committers. This gem will be fully available soon, when the next Pry version (0.9.8) is released.**
10
+
11
+
8
12
  pry-stack_explorer is a plugin for the [Pry](http://pry.github.com)
9
13
  REPL that enables the user to navigate the call-stack.
10
14
 
@@ -26,7 +26,7 @@ module PryStackExplorer
26
26
  # @param [Pry] _pry_ The Pry instance associated with the frame
27
27
  # managers
28
28
  # @return [Array] The stack of Pry::FrameManager objections
29
- def self.all_frame_managers(_pry_)
29
+ def self.frame_managers(_pry_)
30
30
  init_frame_hash
31
31
  Thread.current[:__pry_frame_managers__][_pry_]
32
32
  end
@@ -45,6 +45,8 @@ module PryStackExplorer
45
45
  Thread.current[:__pry_frame_managers__][_pry_].clear
46
46
  end
47
47
 
48
+ class << self; alias_method :delete_frame_managers, :clear_frame_managers; end
49
+
48
50
  # @return [PryStackExplorer::FrameManager] The currently active frame manager
49
51
  def self.frame_manager(_pry_)
50
52
  init_frame_hash
@@ -67,7 +69,9 @@ Pry.config.hooks.add_hook(:after_session, :delete_frame_manager) do |_, _, _pry_
67
69
  end
68
70
 
69
71
  Pry.config.hooks.add_hook(:when_started, :save_caller_bindings) do |binding_stack, options, _pry_|
70
- options[:call_stack] = true unless options.has_key?(:call_stack)
72
+ options[:call_stack] = true unless options.has_key?(:call_stack)
73
+ options[:initial_frame] = 0 unless options.has_key?(:initial_frame)
74
+ initial_frame = options[:initial_frame]
71
75
 
72
76
  next if !options[:call_stack]
73
77
 
@@ -94,8 +98,9 @@ Pry.config.hooks.add_hook(:when_started, :save_caller_bindings) do |binding_stac
94
98
  end
95
99
  end
96
100
 
97
- binding_stack.replace([bindings.first])
101
+ binding_stack.replace [bindings[initial_frame]]
98
102
  PryStackExplorer.create_and_push_frame_manager(bindings, _pry_)
103
+ PryStackExplorer.frame_manager(_pry_).set_binding_index_safely(initial_frame)
99
104
  end
100
105
 
101
106
  # Import the StackExplorer commands
@@ -21,7 +21,7 @@ module PryStackExplorer
21
21
  else
22
22
  binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
23
23
  if binding_index - inc < 0
24
- output.puts "Warning: At bottom of stack, cannot go further!"
24
+ raise Pry::CommandError, "At bottom of stack, cannot go further!"
25
25
  else
26
26
  PryStackExplorer.frame_manager(_pry_).change_frame_to binding_index - inc
27
27
  end
@@ -41,8 +41,8 @@ module PryStackExplorer
41
41
 
42
42
  # Ensure the Pry instance's active binding is the frame manager's
43
43
  # active binding.
44
- def refresh_frame
45
- change_frame_to binding_index
44
+ def refresh_frame(run_whereami=true)
45
+ change_frame_to binding_index, run_whereami
46
46
  end
47
47
 
48
48
  # @return [Binding] The currently active frame
@@ -50,24 +50,36 @@ module PryStackExplorer
50
50
  bindings[binding_index]
51
51
  end
52
52
 
53
- # Change active frame to the one indexed by `index`.
54
- # Note that indexing base is `0`
55
- # @param [Fixnum] index The index of the frame.
56
- def change_frame_to(index)
57
-
53
+ # Set the binding index (aka frame index), but raising an Exception when invalid
54
+ # index received. Also converts negative indices to their positive counterparts.
55
+ # @param [Fixnum] index The index.
56
+ def set_binding_index_safely(index)
58
57
  if index > bindings.size - 1
59
- @pry.output.puts "Warning: At top of stack, cannot go further!"
58
+ raise Pry::CommandError, "At top of stack, cannot go further!"
60
59
  elsif index < -bindings.size
61
- @pry.output.puts "Warning: At bottom of stack, cannot go further!"
60
+ raise Pry::CommandError, "At bottom of stack, cannot go further!"
62
61
  else
63
62
  # wrap around negative indices
64
63
  index = (bindings.size - 1) + index + 1 if index < 0
65
64
 
66
65
  self.binding_index = index
67
- @pry.binding_stack[-1] = bindings[binding_index]
66
+ end
67
+ end
68
68
 
69
- @pry.run_command "whereami"
69
+ # Change active frame to the one indexed by `index`.
70
+ # Note that indexing base is `0`
71
+ # @param [Fixnum] index The index of the frame.
72
+ def change_frame_to(index, run_whereami=true)
73
+
74
+ set_binding_index_safely(index)
75
+
76
+ if @pry.binding_stack.empty?
77
+ @pry.binding_stack.replace [bindings[binding_index]]
78
+ else
79
+ @pry.binding_stack[-1] = bindings[binding_index]
70
80
  end
81
+
82
+ @pry.run_command "whereami" if run_whereami
71
83
  end
72
84
 
73
85
  end
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = "0.2.8pre8"
2
+ VERSION = "0.2.8pre9"
3
3
  end
@@ -2,20 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry-stack_explorer"
5
- s.version = "0.2.8pre8"
5
+ s.version = "0.2.8pre9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2012-01-05"
9
+ s.date = "2012-01-08"
10
10
  s.description = "Walk the stack in a Pry session"
11
11
  s.email = "jrmair@gmail.com"
12
- s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example.rb", "examples/example2.rb", "lib/pry-stack_explorer.rb", "lib/pry-stack_explorer/commands.rb", "lib/pry-stack_explorer/frame_manager.rb", "lib/pry-stack_explorer/version.rb", "pry-stack_explorer.gemspec", "test/helper.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb", "tester.rb"]
12
+ s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example.rb", "examples/example2.rb", "lib/pry-stack_explorer.rb", "lib/pry-stack_explorer/commands.rb", "lib/pry-stack_explorer/frame_manager.rb", "lib/pry-stack_explorer/version.rb", "pry-stack_explorer.gemspec", "test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb", "tester.rb"]
13
13
  s.homepage = "https://github.com/banister"
14
14
  s.require_paths = ["lib"]
15
15
  s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
16
16
  s.rubygems_version = "1.8.11"
17
17
  s.summary = "Walk the stack in a Pry session"
18
- s.test_files = ["test/helper.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb"]
18
+ s.test_files = ["test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb"]
19
19
 
20
20
  if s.respond_to? :specification_version then
21
21
  s.specification_version = 3
data/test/helper.rb CHANGED
@@ -29,10 +29,9 @@ class << Pry
29
29
  end
30
30
  end
31
31
 
32
- #Pry.config.hooks.clear(:before_session)
33
-
34
32
  AfterSessionHook = Pry.config.hooks.get_hook(:after_session, :delete_frame_manager)
35
33
  WhenStartedHook = Pry.config.hooks.get_hook(:when_started, :save_caller_bindings)
34
+
36
35
  Pry.reset_defaults
37
36
 
38
37
  class InputTester
@@ -0,0 +1,130 @@
1
+ require 'helper'
2
+
3
+ describe PryStackExplorer::StackCommands do
4
+
5
+ before do
6
+ Pry.config.hooks.add_hook(:when_started, :save_caller_bindings, &WhenStartedHook)
7
+ Pry.config.hooks.add_hook(:after_session, :delete_frame_manager, &AfterSessionHook)
8
+
9
+ @o = Object.new
10
+ class << @o; attr_accessor :first_method, :second_method, :third_method; end
11
+ def @o.bing() bong end
12
+ def @o.bong() bang end
13
+ def @o.bang() Pry.start(binding) end
14
+ end
15
+
16
+ after do
17
+ Pry.config.hooks.delete_hook(:when_started, :save_caller_bindings)
18
+ Pry.config.hooks.delete_hook(:after_session, :delete_frame_manager)
19
+ end
20
+
21
+ describe "up" do
22
+ it 'should move up the call stack one frame at a time' do
23
+ redirect_pry_io(InputTester.new("@first_method = __method__",
24
+ "up",
25
+ "@second_method = __method__",
26
+ "up",
27
+ "@third_method = __method__",
28
+ "exit-all"), out=StringIO.new) do
29
+ @o.bing
30
+ end
31
+
32
+ @o.first_method.should == :bang
33
+ @o.second_method.should == :bong
34
+ @o.third_method.should == :bing
35
+ end
36
+
37
+ it 'should move up the call stack two frames at a time' do
38
+ redirect_pry_io(InputTester.new("@first_method = __method__",
39
+ "up 2",
40
+ "@second_method = __method__",
41
+ "exit-all"), out=StringIO.new) do
42
+ @o.bing
43
+ end
44
+
45
+ @o.first_method.should == :bang
46
+ @o.second_method.should == :bing
47
+ end
48
+ end
49
+
50
+ describe "down" do
51
+ it 'should move down the call stack one frame at a time' do
52
+ def @o.bang() Pry.start(binding, :initial_frame => 1) end
53
+
54
+ redirect_pry_io(InputTester.new("@first_method = __method__",
55
+ "down",
56
+ "@second_method = __method__",
57
+ "exit-all"), out=StringIO.new) do
58
+ @o.bing
59
+ end
60
+
61
+ @o.first_method.should == :bong
62
+ @o.second_method.should == :bang
63
+ end
64
+
65
+ it 'should move down the call stack two frames at a time' do
66
+ def @o.bang() Pry.start(binding, :initial_frame => 2) end
67
+
68
+ redirect_pry_io(InputTester.new("@first_method = __method__",
69
+ "down 2",
70
+ "@second_method = __method__",
71
+ "exit-all"), out=StringIO.new) do
72
+ @o.bing
73
+ end
74
+
75
+ @o.first_method.should == :bing
76
+ @o.second_method.should == :bang
77
+ end
78
+ end
79
+
80
+ describe "frame" do
81
+ it 'should move to the given frame in the call stack' do
82
+ redirect_pry_io(InputTester.new("frame 2",
83
+ "@first_method = __method__",
84
+ "exit-all"), out=StringIO.new) do
85
+ @o.bing
86
+ end
87
+
88
+ @o.first_method.should == :bing
89
+ end
90
+
91
+ describe "negative indices" do
92
+ it 'should work with negative frame numbers' do
93
+ o = Object.new
94
+ class << o; attr_accessor :frame; end
95
+ def o.alpha() binding end
96
+ def o.beta() binding end
97
+ def o.gamma() binding end
98
+
99
+ call_stack = [o.alpha, o.beta, o.gamma]
100
+ method_names = call_stack.map { |v| v.eval('__method__') }.reverse
101
+ (1..3).each_with_index do |v, idx|
102
+ redirect_pry_io(InputTester.new("frame -#{v}",
103
+ "@frame = __method__",
104
+ "exit-all"), out=StringIO.new) do
105
+ Pry.start(o, :call_stack => call_stack)
106
+ end
107
+ o.frame.should == method_names[idx]
108
+ end
109
+ end
110
+
111
+ it 'should convert negative indices to their positive counterparts' do
112
+ o = Object.new
113
+ class << o; attr_accessor :frame_number; end
114
+ def o.alpha() binding end
115
+ def o.beta() binding end
116
+ def o.gamma() binding end
117
+
118
+ call_stack = [o.alpha, o.beta, o.gamma]
119
+ (1..3).each_with_index do |v, idx|
120
+ redirect_pry_io(InputTester.new("frame -#{v}",
121
+ "@frame_number = PryStackExplorer.frame_manager(_pry_).binding_index",
122
+ "exit-all"), out=StringIO.new) do
123
+ Pry.start(o, :call_stack => call_stack)
124
+ end
125
+ o.frame_number.should == call_stack.size - v
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,168 +1,210 @@
1
- require 'helper'
2
-
3
- describe PryStackExplorer do
4
-
5
- describe "Pry.start" do
6
- before do
7
- Pry.config.hooks.add_hook(:when_started, :save_caller_bindings, &WhenStartedHook)
8
- Pry.config.hooks.add_hook(:after_session, :delete_frame_manager, &AfterSessionHook)
9
- end
10
-
11
- after do
12
- Pry.config.hooks.delete_hook(:when_started, :save_caller_bindings)
13
- Pry.config.hooks.delete_hook(:after_session, :delete_frame_manager)
14
- end
15
-
16
- it 'should invoke a session with the call stack set' do
17
- o = Object.new
18
- def o.bing() bong end
19
- def o.bong() bang end
20
- def o.bang() Pry.start(binding) end
21
-
22
- redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
23
- o.bing
24
- end
25
-
26
- out.string.should =~ /bang.*?bong.*?bing/m
27
- end
28
-
29
- it 'should set no call stack when :call_stack => false' do
30
- o = Object.new
31
- def o.bing() bong end
32
- def o.bong() bang end
33
- def o.bang() Pry.start(binding, :call_stack => false) end
34
-
35
- redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
36
- o.bing
37
- end
38
-
39
- out.string.should =~ /No caller stack/
40
- end
41
-
42
- it 'should set custom call stack when :call_stack => [b1, b2]' do
43
- o = Object.new
44
- def o.alpha() binding end
45
- def o.beta() binding end
46
- def o.gamma() binding end
47
-
48
- redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
49
- Pry.start(binding, :call_stack => [o.beta, o.gamma, o.alpha])
50
- end
51
-
52
- out.string.should =~ /beta.*?gamma.*?alpha/m
53
- end
54
-
55
- it 'should raise if custom call stack does not contain bindings or is empty' do
56
- redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
57
- lambda { Pry.start(binding, :call_stack => [1, 2, 3]) }.should.raise ArgumentError
58
- end
59
-
60
- redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
61
- lambda { Pry.start(binding, :call_stack => []) }.should.raise ArgumentError
62
- end
63
- end
64
- end
65
-
66
- describe "unit tests for PryStackExplorer class methods" do
67
- before do
68
- @pry_instance = Pry.new
69
- @bindings = [binding, binding]
70
- end
71
-
72
- after do
73
- PE.clear_frame_managers(@pry_instance)
74
- end
75
-
76
- describe "PryStackExplorer.create_and_push_frame_manager" do
77
-
78
- it "should create and push one new FrameManager" do
79
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
80
- PE.frame_manager(@pry_instance).is_a?(PE::FrameManager).should == true
81
- PE.all_frame_managers(@pry_instance).count.should == 1
82
- end
83
-
84
- it "should create and push multiple FrameManagers" do
85
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
86
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
87
- PE.all_frame_managers(@pry_instance).count.should == 2
88
- end
89
-
90
- it 'should push FrameManagers to stacks based on Pry instance' do
91
- p2 = Pry.new
92
- bindings = [binding, binding]
93
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
94
- PE.create_and_push_frame_manager(bindings, p2)
95
- PE.all_frame_managers(@pry_instance).count.should == 1
96
- PE.all_frame_managers(p2).count.should == 1
97
- end
98
- end
99
-
100
- describe "PryStackExplorer.frame_manager" do
101
- it "should have the correct bindings" do
102
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
103
- PE.frame_manager(@pry_instance).bindings.should == @bindings
104
- end
105
-
106
- it "should return the last pushed FrameManager" do
107
- bindings = [binding, binding]
108
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
109
- PE.create_and_push_frame_manager(bindings, @pry_instance)
110
- PE.frame_manager(@pry_instance).bindings.should == bindings
111
- end
112
-
113
- it "should return the correct FrameManager for the given Pry instance" do
114
- bindings = [binding, binding]
115
- p2 = Pry.new
116
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
117
- PE.create_and_push_frame_manager(bindings, p2)
118
- PE.frame_manager(@pry_instance).bindings.should == @bindings
119
- PE.frame_manager(p2).bindings.should == bindings
120
- end
121
- end
122
-
123
- describe "PryStackExplorer.pop_frame_manager" do
124
- it "should remove FrameManager from stack" do
125
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
126
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
127
- PE.pop_frame_manager(@pry_instance)
128
- PE.all_frame_managers(@pry_instance).count.should == 1
129
- end
130
-
131
- it "should return the most recently added FrameManager" do
132
- bindings = [binding, binding]
133
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
134
- PE.create_and_push_frame_manager(bindings, @pry_instance)
135
- PE.pop_frame_manager(@pry_instance).bindings.should == bindings
136
- end
137
-
138
- it "should remove FrameManager from the appropriate stack based on Pry instance" do
139
- p2 = Pry.new
140
- bindings = [binding, binding]
141
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
142
- PE.create_and_push_frame_manager(bindings, p2)
143
- PE.pop_frame_manager(@pry_instance)
144
- PE.all_frame_managers(@pry_instance).count.should == 0
145
- PE.all_frame_managers(p2).count.should == 1
146
- end
147
- end
148
-
149
- describe "PryStackExplorer.clear_frame_managers" do
150
- it "should clear all FrameManagers for a Pry instance" do
151
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
152
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
153
- PE.clear_frame_managers(@pry_instance)
154
- PE.all_frame_managers(@pry_instance).count.should == 0
155
- end
156
-
157
- it "should clear all FrameManagers for a Pry instance" do
158
- p2 = Pry.new
159
- bindings = [binding, binding]
160
- PE.create_and_push_frame_manager(@bindings, @pry_instance)
161
- PE.create_and_push_frame_manager(bindings, p2)
162
- PE.clear_frame_managers(@pry_instance)
163
- PE.all_frame_managers(p2).count.should == 1
164
- PE.all_frame_managers(@pry_instance).count.should == 0
165
- end
166
- end
167
- end
168
- end
1
+ require 'helper'
2
+
3
+ describe PryStackExplorer do
4
+
5
+ describe "Pry.start" do
6
+ before do
7
+ Pry.config.hooks.add_hook(:when_started, :save_caller_bindings, &WhenStartedHook)
8
+ Pry.config.hooks.add_hook(:after_session, :delete_frame_manager, &AfterSessionHook)
9
+
10
+ @o = Object.new
11
+ class << @o; attr_reader :frame; end
12
+ def @o.bing() bong end
13
+ def @o.bong() bang end
14
+ def @o.bang() Pry.start(binding) end
15
+ end
16
+
17
+ after do
18
+ Pry.config.hooks.delete_hook(:when_started, :save_caller_bindings)
19
+ Pry.config.hooks.delete_hook(:after_session, :delete_frame_manager)
20
+ end
21
+
22
+ describe ":initial_frame option" do
23
+ it 'should default to first frame when no option provided' do
24
+ redirect_pry_io(StringIO.new("@frame = __method__\nexit\n"), out=StringIO.new) do
25
+ @o.bing
26
+ end
27
+
28
+ @o.frame.should == :bang
29
+ end
30
+
31
+ it 'should begin session at specified frame' do
32
+ o = Object.new
33
+ class << o; attr_reader :frame; end
34
+ def o.bing() bong end
35
+ def o.bong() bang end
36
+ def o.bang() Pry.start(binding, :initial_frame => 1) end
37
+
38
+ redirect_pry_io(StringIO.new("@frame = __method__\nexit\n"), out=StringIO.new) do
39
+ o.bing
40
+ end
41
+
42
+ o.frame.should == :bong
43
+ end
44
+
45
+ it 'should begin session at specified frame when using :call_stack' do
46
+ o = Object.new
47
+ class << o; attr_accessor :frame; end
48
+ def o.alpha() binding end
49
+ def o.beta() binding end
50
+ def o.gamma() binding end
51
+
52
+ redirect_pry_io(StringIO.new("@frame = __method__\nexit\n"), out=StringIO.new) do
53
+ Pry.start(binding, :call_stack => [o.gamma, o.beta, o.alpha], :initial_frame => 1)
54
+ end
55
+
56
+ o.frame.should == :beta
57
+ end
58
+
59
+ end
60
+
61
+ describe ":call_stack option" do
62
+ it 'should invoke a session with the call stack set' do
63
+ redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
64
+ @o.bing
65
+ end
66
+
67
+ out.string.should =~ /bang.*?bong.*?bing/m
68
+ end
69
+
70
+ it 'should set no call stack when :call_stack => false' do
71
+ o = Object.new
72
+ def o.bing() bong end
73
+ def o.bong() bang end
74
+ def o.bang() Pry.start(binding, :call_stack => false) end
75
+
76
+ redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
77
+ o.bing
78
+ end
79
+
80
+ out.string.should =~ /No caller stack/
81
+ end
82
+
83
+ it 'should set custom call stack when :call_stack => [b1, b2]' do
84
+ o = Object.new
85
+ def o.alpha() binding end
86
+ def o.beta() binding end
87
+ def o.gamma() binding end
88
+
89
+ redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
90
+ Pry.start(binding, :call_stack => [o.beta, o.gamma, o.alpha])
91
+ end
92
+
93
+ out.string.should =~ /beta.*?gamma.*?alpha/m
94
+ end
95
+
96
+ it 'should raise if custom call stack does not contain bindings or is empty' do
97
+ redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
98
+ lambda { Pry.start(binding, :call_stack => [1, 2, 3]) }.should.raise ArgumentError
99
+ end
100
+
101
+ redirect_pry_io(StringIO.new("show-stack\nexit\n"), out=StringIO.new) do
102
+ lambda { Pry.start(binding, :call_stack => []) }.should.raise ArgumentError
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "unit tests for PryStackExplorer class methods" do
109
+ before do
110
+ @pry_instance = Pry.new
111
+ @bindings = [binding, binding]
112
+ end
113
+
114
+ after do
115
+ PE.clear_frame_managers(@pry_instance)
116
+ end
117
+
118
+ describe "PryStackExplorer.create_and_push_frame_manager" do
119
+
120
+ it "should create and push one new FrameManager" do
121
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
122
+ PE.frame_manager(@pry_instance).is_a?(PE::FrameManager).should == true
123
+ PE.frame_managers(@pry_instance).count.should == 1
124
+ end
125
+
126
+ it "should create and push multiple FrameManagers" do
127
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
128
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
129
+ PE.frame_managers(@pry_instance).count.should == 2
130
+ end
131
+
132
+ it 'should push FrameManagers to stacks based on Pry instance' do
133
+ p2 = Pry.new
134
+ bindings = [binding, binding]
135
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
136
+ PE.create_and_push_frame_manager(bindings, p2)
137
+ PE.frame_managers(@pry_instance).count.should == 1
138
+ PE.frame_managers(p2).count.should == 1
139
+ end
140
+ end
141
+
142
+ describe "PryStackExplorer.frame_manager" do
143
+ it "should have the correct bindings" do
144
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
145
+ PE.frame_manager(@pry_instance).bindings.should == @bindings
146
+ end
147
+
148
+ it "should return the last pushed FrameManager" do
149
+ bindings = [binding, binding]
150
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
151
+ PE.create_and_push_frame_manager(bindings, @pry_instance)
152
+ PE.frame_manager(@pry_instance).bindings.should == bindings
153
+ end
154
+
155
+ it "should return the correct FrameManager for the given Pry instance" do
156
+ bindings = [binding, binding]
157
+ p2 = Pry.new
158
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
159
+ PE.create_and_push_frame_manager(bindings, p2)
160
+ PE.frame_manager(@pry_instance).bindings.should == @bindings
161
+ PE.frame_manager(p2).bindings.should == bindings
162
+ end
163
+ end
164
+
165
+ describe "PryStackExplorer.pop_frame_manager" do
166
+ it "should remove FrameManager from stack" do
167
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
168
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
169
+ PE.pop_frame_manager(@pry_instance)
170
+ PE.frame_managers(@pry_instance).count.should == 1
171
+ end
172
+
173
+ it "should return the most recently added FrameManager" do
174
+ bindings = [binding, binding]
175
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
176
+ PE.create_and_push_frame_manager(bindings, @pry_instance)
177
+ PE.pop_frame_manager(@pry_instance).bindings.should == bindings
178
+ end
179
+
180
+ it "should remove FrameManager from the appropriate stack based on Pry instance" do
181
+ p2 = Pry.new
182
+ bindings = [binding, binding]
183
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
184
+ PE.create_and_push_frame_manager(bindings, p2)
185
+ PE.pop_frame_manager(@pry_instance)
186
+ PE.frame_managers(@pry_instance).count.should == 0
187
+ PE.frame_managers(p2).count.should == 1
188
+ end
189
+ end
190
+
191
+ describe "PryStackExplorer.clear_frame_managers" do
192
+ it "should clear all FrameManagers for a Pry instance" do
193
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
194
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
195
+ PE.clear_frame_managers(@pry_instance)
196
+ PE.frame_managers(@pry_instance).count.should == 0
197
+ end
198
+
199
+ it "should clear all FrameManagers for a Pry instance" do
200
+ p2 = Pry.new
201
+ bindings = [binding, binding]
202
+ PE.create_and_push_frame_manager(@bindings, @pry_instance)
203
+ PE.create_and_push_frame_manager(bindings, p2)
204
+ PE.clear_frame_managers(@pry_instance)
205
+ PE.frame_managers(p2).count.should == 1
206
+ PE.frame_managers(@pry_instance).count.should == 0
207
+ end
208
+ end
209
+ end
210
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pry-stack_explorer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 5
5
- version: 0.2.8pre8
5
+ version: 0.2.8pre9
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Mair (banisterfiend)
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-05 00:00:00 Z
13
+ date: 2012-01-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: binding_of_caller
@@ -82,6 +82,7 @@ files:
82
82
  - lib/pry-stack_explorer/version.rb
83
83
  - pry-stack_explorer.gemspec
84
84
  - test/helper.rb
85
+ - test/test_commands.rb
85
86
  - test/test_frame_manager.rb
86
87
  - test/test_stack_explorer.rb
87
88
  - tester.rb
@@ -114,5 +115,6 @@ specification_version: 3
114
115
  summary: Walk the stack in a Pry session
115
116
  test_files:
116
117
  - test/helper.rb
118
+ - test/test_commands.rb
117
119
  - test/test_frame_manager.rb
118
120
  - test/test_stack_explorer.rb