pry 0.10.2-i386-mingw32 → 1.0.0.pre1-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -0,0 +1,247 @@
1
+ require 'helper'
2
+
3
+ describe "amend-line" do
4
+ before do
5
+ @t = pry_tester
6
+ end
7
+
8
+ it 'should amend the last line of input when no line number specified' do
9
+ @t.push *unindent(<<-STR).split("\n")
10
+ def hello
11
+ puts :bing
12
+ STR
13
+
14
+ @t.process_command 'amend-line puts :blah'
15
+
16
+ @t.eval_string.should == unindent(<<-STR)
17
+ def hello
18
+ puts :blah
19
+ STR
20
+ end
21
+
22
+ it 'should amend the specified line of input when line number given' do
23
+ @t.push *unindent(<<-STR).split("\n")
24
+ def hello
25
+ puts :bing
26
+ puts :bang
27
+ STR
28
+
29
+ @t.process_command 'amend-line 1 def goodbye'
30
+
31
+ @t.eval_string.should == unindent(<<-STR)
32
+ def goodbye
33
+ puts :bing
34
+ puts :bang
35
+ STR
36
+ end
37
+
38
+ it 'should amend the first line of input when 0 given as line number' do
39
+ @t.push *unindent(<<-STR).split("\n")
40
+ def hello
41
+ puts :bing
42
+ puts :bang
43
+ STR
44
+
45
+ @t.process_command 'amend-line 0 def goodbye'
46
+
47
+ @t.eval_string.should == unindent(<<-STR)
48
+ def goodbye
49
+ puts :bing
50
+ puts :bang
51
+ STR
52
+ end
53
+
54
+ it 'should amend a specified line when negative number given' do
55
+ @t.push *unindent(<<-STR).split("\n")
56
+ def hello
57
+ puts :bing
58
+ puts :bang
59
+ STR
60
+
61
+ @t.process_command 'amend-line -1 puts :bink'
62
+
63
+ @t.eval_string.should == unindent(<<-STR)
64
+ def hello
65
+ puts :bing
66
+ puts :bink
67
+ STR
68
+
69
+ @t.process_command 'amend-line -2 puts :bink'
70
+
71
+ @t.eval_string.should == unindent(<<-STR)
72
+ def hello
73
+ puts :bink
74
+ puts :bink
75
+ STR
76
+ end
77
+
78
+ it 'should amend a range of lines of input when negative numbers given' do
79
+ @t.push *unindent(<<-STR).split("\n")
80
+ def hello
81
+ puts :bing
82
+ puts :bang
83
+ puts :boat
84
+ STR
85
+
86
+ @t.process_command 'amend-line -3..-2 puts :bink'
87
+
88
+ @t.eval_string.should == unindent(<<-STR)
89
+ def hello
90
+ puts :bink
91
+ puts :boat
92
+ STR
93
+ end
94
+
95
+ it 'should correctly amend the specified line with interpolated text' do
96
+ @t.push *unindent(<<-STR).split("\n")
97
+ def hello
98
+ puts :bing
99
+ puts :bang
100
+ STR
101
+
102
+ @t.process_command 'amend-line puts "#{goodbye}"'
103
+
104
+ @t.eval_string.should == unindent(<<-'STR')
105
+ def hello
106
+ puts :bing
107
+ puts "#{goodbye}"
108
+ STR
109
+ end
110
+
111
+ it 'should display error if nothing to amend' do
112
+ error = nil
113
+
114
+ begin
115
+ @t.process_command 'amend-line'
116
+ rescue Pry::CommandError => e
117
+ error = e
118
+ end
119
+
120
+ error.should.not.be.nil
121
+ error.message.should =~ /No input to amend/
122
+ end
123
+
124
+ it 'should correctly amend the specified range of lines' do
125
+ @t.push *unindent(<<-STR).split("\n")
126
+ def hello
127
+ puts :bing
128
+ puts :bang
129
+ puts :heart
130
+ STR
131
+
132
+ @t.process_command 'amend-line 2..3 puts :bong'
133
+
134
+ @t.eval_string.should == unindent(<<-STR)
135
+ def hello
136
+ puts :bong
137
+ puts :heart
138
+ STR
139
+ end
140
+
141
+ it 'should correctly delete a specific line using the ! for content' do
142
+ @t.push *unindent(<<-STR).split("\n")
143
+ def hello
144
+ puts :bing
145
+ puts :bang
146
+ puts :boast
147
+ puts :heart
148
+ STR
149
+
150
+ @t.process_command 'amend-line 3 !'
151
+
152
+ @t.eval_string.should == unindent(<<-STR)
153
+ def hello
154
+ puts :bing
155
+ puts :boast
156
+ puts :heart
157
+ STR
158
+ end
159
+
160
+ it 'should correctly delete a range of lines using the ! for content' do
161
+ @t.push *unindent(<<-STR).split("\n")
162
+ def hello
163
+ puts :bing
164
+ puts :bang
165
+ puts :boast
166
+ puts :heart
167
+ STR
168
+
169
+ @t.process_command 'amend-line 2..4 !'
170
+
171
+ @t.eval_string.should == unindent(<<-STR)
172
+ def hello
173
+ puts :heart
174
+ STR
175
+ end
176
+
177
+ it 'should correctly delete the previous line using the ! for content' do
178
+ @t.push *unindent(<<-STR).split("\n")
179
+ def hello
180
+ puts :bing
181
+ puts :bang
182
+ puts :boast
183
+ puts :heart
184
+ STR
185
+
186
+ @t.process_command 'amend-line !'
187
+
188
+ @t.eval_string.should == unindent(<<-STR)
189
+ def hello
190
+ puts :bing
191
+ puts :bang
192
+ puts :boast
193
+ STR
194
+ end
195
+
196
+ it 'should amend the specified range of lines, with numbers < 0 in range' do
197
+ @t.push *unindent(<<-STR).split("\n")
198
+ def hello
199
+ puts :bing
200
+ puts :bang
201
+ puts :boast
202
+ puts :heart
203
+ STR
204
+
205
+ @t.process_command 'amend-line 2..-2 puts :bong'
206
+
207
+ @t.eval_string.should == unindent(<<-STR)
208
+ def hello
209
+ puts :bong
210
+ puts :heart
211
+ STR
212
+ end
213
+
214
+ it 'should correctly insert a line before a specified line using >' do
215
+ @t.push *unindent(<<-STR).split("\n")
216
+ def hello
217
+ puts :bing
218
+ puts :bang
219
+ STR
220
+
221
+ @t.process_command 'amend-line 2 > puts :inserted'
222
+
223
+ @t.eval_string.should == unindent(<<-STR)
224
+ def hello
225
+ puts :inserted
226
+ puts :bing
227
+ puts :bang
228
+ STR
229
+ end
230
+
231
+ it 'should ignore second value of range with > syntax' do
232
+ @t.push *unindent(<<-STR).split("\n")
233
+ def hello
234
+ puts :bing
235
+ puts :bang
236
+ STR
237
+
238
+ @t.process_command 'amend-line 2..21 > puts :inserted'
239
+
240
+ @t.eval_string.should == unindent(<<-STR)
241
+ def hello
242
+ puts :inserted
243
+ puts :bing
244
+ puts :bang
245
+ STR
246
+ end
247
+ end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+
3
+ describe "!" do
4
+ before do
5
+ @t = pry_tester
6
+ end
7
+
8
+ it 'should correctly clear the input buffer ' do
9
+ @t.push unindent(<<-STR)
10
+ def hello
11
+ puts :bing
12
+ STR
13
+
14
+ @t.process_command '!'
15
+ @t.last_output.should =~ /Input buffer cleared!/
16
+ @t.eval_string.should == ''
17
+ end
18
+ end
@@ -0,0 +1,164 @@
1
+ require 'helper'
2
+
3
+ describe "cat" do
4
+ before do
5
+ @str_output = StringIO.new
6
+
7
+ @t = pry_tester do
8
+ def insert_nil_input
9
+ @pry.update_input_history(nil)
10
+ end
11
+
12
+ def last_exception=(e)
13
+ @pry.last_exception = e
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "on receiving a file that does not exist" do
19
+ it 'should display an error message' do
20
+ proc {
21
+ @t.eval 'cat supercalifragilicious66'
22
+ }.should.raise(StandardError).message.should =~ /Cannot open/
23
+ end
24
+ end
25
+
26
+ describe "with --in" do
27
+ it 'should display the last few expressions with indices' do
28
+ @t.eval('10', '20', 'cat --in').should == unindent(<<-STR)
29
+ 1:
30
+ 10
31
+ 2:
32
+ 20
33
+ STR
34
+ end
35
+ end
36
+
37
+ describe "with --in 1" do
38
+ it 'should display the first expression with no index' do
39
+ @t.eval('10', '20', 'cat --in 1').should == "10\n"
40
+ end
41
+ end
42
+
43
+ describe "with --in -1" do
44
+ it 'should display the last expression with no index' do
45
+ @t.eval('10', '20', 'cat --in -1').should == "20\n"
46
+ end
47
+ end
48
+
49
+ describe "with --in 1..2" do
50
+ it 'should display the given range with indices, omitting nils' do
51
+ @t.eval '10'
52
+ @t.insert_nil_input # normally happens when a command is executed
53
+ @t.eval ':hello'
54
+
55
+ @t.eval('cat --in 1..3').should == unindent(<<-EOS)
56
+ 1:
57
+ 10
58
+ 3:
59
+ :hello
60
+ EOS
61
+ end
62
+ end
63
+
64
+ # this doesnt work so well on rbx due to differences in backtrace
65
+ # so we currently skip rbx until we figure out a workaround
66
+ describe "with --ex" do
67
+ before do
68
+ @o = Object.new
69
+
70
+ # this is to test exception code (cat --ex)
71
+ def @o.broken_method
72
+ this method is broken
73
+ end
74
+ end
75
+
76
+ if !Pry::Helpers::BaseHelpers.rbx?
77
+ it 'cat --ex should display repl code that generated exception' do
78
+ @t.eval unindent(<<-EOS)
79
+ begin
80
+ this raises error
81
+ rescue => e
82
+ _pry_.last_exception = e
83
+ end
84
+ EOS
85
+ @t.eval('cat --ex').should =~ /\d+:(\s*) this raises error/
86
+ end
87
+
88
+ it 'cat --ex should correctly display code that generated exception' do
89
+ begin
90
+ @o.broken_method
91
+ rescue => e
92
+ @t.last_exception = e
93
+ end
94
+ @t.eval('cat --ex').should =~ /this method is broken/
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "with --ex N" do
100
+ it 'should cat first level of backtrace when --ex used with no argument ' do
101
+ temp_file do |f|
102
+ f << "bt number 1"
103
+ f.flush
104
+ @t.last_exception = mock_exception("#{f.path}:1", 'x', 'x')
105
+ @t.eval('cat --ex').should =~ /bt number 1/
106
+ end
107
+ end
108
+
109
+ it 'should cat first level of backtrace when --ex 0 used ' do
110
+ temp_file do |f|
111
+ f << "bt number 1"
112
+ f.flush
113
+ @t.last_exception = mock_exception("#{f.path}:1", 'x', 'x')
114
+ @t.eval('cat --ex 0').should =~ /bt number 1/
115
+ end
116
+ end
117
+
118
+ it 'should cat second level of backtrace when --ex 1 used ' do
119
+ temp_file do |f|
120
+ f << "bt number 2"
121
+ f.flush
122
+ @t.last_exception = mock_exception('x', "#{f.path}:1", 'x')
123
+ @t.eval('cat --ex 1').should =~ /bt number 2/
124
+ end
125
+ end
126
+
127
+ it 'should cat third level of backtrace when --ex 2 used' do
128
+ temp_file do |f|
129
+ f << "bt number 3"
130
+ f.flush
131
+ @t.last_exception = mock_exception('x', 'x', "#{f.path}:1")
132
+ @t.eval('cat --ex 2').should =~ /bt number 3/
133
+ end
134
+ end
135
+
136
+ it 'should show error when backtrace level out of bounds' do
137
+ @t.last_exception = mock_exception('x', 'x', 'x')
138
+ proc {
139
+ @t.eval('cat --ex 3')
140
+ }.should.raise(Pry::CommandError).message.should =~ /out of bounds/
141
+ end
142
+
143
+ it 'each successive cat --ex should show the next level of backtrace, and going past the final level should return to the first' do
144
+ temp_files = []
145
+ 3.times do |i|
146
+ temp_files << Tempfile.new(['pry', '.rb'])
147
+ temp_files.last << "bt number #{i}"
148
+ temp_files.last.flush
149
+ end
150
+
151
+ @t.last_exception = mock_exception(*temp_files.map { |f| "#{f.path}:1" })
152
+
153
+ 3.times do |i|
154
+ @t.eval('cat --ex').should =~ /bt number #{i}/
155
+ end
156
+
157
+ @t.eval('cat --ex').should =~ /bt number 0/
158
+
159
+ temp_files.each do |file|
160
+ file.close(true)
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,250 @@
1
+ require 'helper'
2
+
3
+ describe 'cd' do
4
+ before do
5
+ @o, @obj = Object.new, Object.new
6
+ @obj.instance_variable_set(:@x, 66)
7
+ @obj.instance_variable_set(:@y, 79)
8
+ @o.instance_variable_set(:@obj, @obj)
9
+
10
+ @t = pry_tester(@o) do
11
+ def assert_binding_stack(other)
12
+ binding_stack.map { |b| b.eval('self') }.should == other
13
+ end
14
+
15
+ def binding_stack
16
+ eval '_pry_.binding_stack.dup'
17
+ end
18
+
19
+ def command_state
20
+ eval '_pry_.command_state["cd"]'
21
+ end
22
+
23
+ def old_stack
24
+ eval '_pry_.command_state["cd"].old_stack.dup'
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'state' do
30
+ it 'should not to be set up in fresh instance' do
31
+ @t.command_state.should.be.nil
32
+ end
33
+ end
34
+
35
+ describe 'old stack toggling with `cd -`' do
36
+ describe 'in fresh pry instance' do
37
+ it 'should not toggle when there is no old stack' do
38
+ 2.times do
39
+ @t.eval 'cd -'
40
+ @t.assert_binding_stack [@o]
41
+ end
42
+ end
43
+ end
44
+
45
+ describe 'when an error was raised' do
46
+ it 'should not toggle and should keep correct stacks' do
47
+ proc {
48
+ @t.eval 'cd @'
49
+ }.should.raise(Pry::CommandError)
50
+
51
+ @t.old_stack.should == []
52
+ @t.assert_binding_stack [@o]
53
+
54
+ @t.eval 'cd -'
55
+ @t.old_stack.should == []
56
+ @t.assert_binding_stack [@o]
57
+ end
58
+ end
59
+
60
+ describe 'when using simple cd syntax' do
61
+ it 'should toggle' do
62
+ @t.eval 'cd :mon_dogg', 'cd -'
63
+ @t.assert_binding_stack [@o]
64
+
65
+ @t.eval 'cd -'
66
+ @t.assert_binding_stack [@o, :mon_dogg]
67
+ end
68
+ end
69
+
70
+ describe "when using complex cd syntax" do
71
+ it 'should toggle with a complex path (simple case)' do
72
+ @t.eval 'cd 1/2/3', 'cd -'
73
+ @t.assert_binding_stack [@o]
74
+
75
+ @t.eval 'cd -'
76
+ @t.assert_binding_stack [@o, 1, 2, 3]
77
+ end
78
+
79
+ it 'should toggle with a complex path (more complex case)' do
80
+ @t.eval 'cd 1/2/3', 'cd ../4', 'cd -'
81
+ @t.assert_binding_stack [@o, 1, 2, 3]
82
+
83
+ @t.eval 'cd -'
84
+ @t.assert_binding_stack [@o, 1, 2, 4]
85
+ end
86
+ end
87
+
88
+ describe 'series of cd calls' do
89
+ it 'should toggle with fuzzy `cd -` calls' do
90
+ @t.eval 'cd :mon_dogg', 'cd -', 'cd 42', 'cd -'
91
+ @t.assert_binding_stack [@o]
92
+
93
+ @t.eval 'cd -'
94
+ @t.assert_binding_stack [@o, 42]
95
+ end
96
+ end
97
+
98
+ describe 'when using cd ..' do
99
+ it 'should toggle with a simple path' do
100
+ @t.eval 'cd :john_dogg', 'cd ..'
101
+ @t.assert_binding_stack [@o]
102
+
103
+ @t.eval 'cd -'
104
+ @t.assert_binding_stack [@o, :john_dogg]
105
+ end
106
+
107
+ it 'should toggle with a complex path' do
108
+ @t.eval 'cd 1/2/3/../4', 'cd -'
109
+ @t.assert_binding_stack [@o]
110
+
111
+ @t.eval 'cd -'
112
+ @t.assert_binding_stack [@o, 1, 2, 4]
113
+ end
114
+ end
115
+
116
+ describe 'when using cd ::' do
117
+ it 'should toggle' do
118
+ @t.eval 'cd ::', 'cd -'
119
+ @t.assert_binding_stack [@o]
120
+
121
+ @t.eval 'cd -'
122
+ @t.assert_binding_stack [@o, TOPLEVEL_BINDING.eval('self')]
123
+ end
124
+ end
125
+
126
+ describe 'when using cd /' do
127
+ it 'should toggle' do
128
+ @t.eval 'cd /', 'cd -'
129
+ @t.assert_binding_stack [@o]
130
+
131
+ @t.eval 'cd :john_dogg', 'cd /', 'cd -'
132
+ @t.assert_binding_stack [@o, :john_dogg]
133
+ end
134
+ end
135
+
136
+ describe 'when using ^D (Control-D) key press' do
137
+ it 'should keep correct old binding' do
138
+ @t.eval 'cd :john_dogg', 'cd :mon_dogg', 'cd :kyr_dogg',
139
+ 'Pry::DEFAULT_CONTROL_D_HANDLER.call("", _pry_)'
140
+ @t.assert_binding_stack [@o, :john_dogg, :mon_dogg]
141
+
142
+ @t.eval 'cd -'
143
+ @t.assert_binding_stack [@o, :john_dogg, :mon_dogg, :kyr_dogg]
144
+
145
+ @t.eval 'cd -'
146
+ @t.assert_binding_stack [@o, :john_dogg, :mon_dogg]
147
+ end
148
+ end
149
+ end
150
+
151
+ it 'should cd into simple input' do
152
+ @t.eval 'cd :mon_ouie'
153
+ @t.eval('self').should == :mon_ouie
154
+ end
155
+
156
+ it 'should break out of session with cd ..' do
157
+ @t.eval 'cd :outer', 'cd :inner'
158
+ @t.eval('self').should == :inner
159
+
160
+ @t.eval 'cd ..'
161
+ @t.eval('self').should == :outer
162
+ end
163
+
164
+ it "should not leave the REPL session when given 'cd ..'" do
165
+ @t.eval 'cd ..'
166
+ @t.eval('self').should == @o
167
+ end
168
+
169
+ it 'should break out to outer-most session with cd /' do
170
+ @t.eval 'cd :inner'
171
+ @t.eval('self').should == :inner
172
+
173
+ @t.eval 'cd 5'
174
+ @t.eval('self').should == 5
175
+
176
+ @t.eval 'cd /'
177
+ @t.eval('self').should == @o
178
+ end
179
+
180
+ it 'should break out to outer-most session with just cd (no args)' do
181
+ @t.eval 'cd :inner'
182
+ @t.eval('self').should == :inner
183
+
184
+ @t.eval 'cd 5'
185
+ @t.eval('self').should == 5
186
+
187
+ @t.eval 'cd'
188
+ @t.eval('self').should == @o
189
+ end
190
+
191
+ it 'should cd into an object and its ivar using cd obj/@ivar syntax' do
192
+ @t.eval 'cd @obj/@x'
193
+ @t.assert_binding_stack [@o, @obj, 66]
194
+ end
195
+
196
+ it 'should cd into an object and its ivar using cd obj/@ivar/ syntax (note following /)' do
197
+ @t.eval 'cd @obj/@x/'
198
+ @t.assert_binding_stack [@o, @obj, 66]
199
+ end
200
+
201
+ it 'should cd into previous object and its local using cd ../local syntax' do
202
+ @t.eval 'cd @obj', 'local = :local', 'cd @x', 'cd ../local'
203
+ @t.assert_binding_stack [@o, @obj, :local]
204
+ end
205
+
206
+ it 'should cd into an object and its ivar and back again using cd obj/@ivar/.. syntax' do
207
+ @t.eval 'cd @obj/@x/..'
208
+ @t.assert_binding_stack [@o, @obj]
209
+ end
210
+
211
+ it 'should cd into an object and its ivar and back and then into another ivar using cd obj/@ivar/../@y syntax' do
212
+ @t.eval 'cd @obj/@x/../@y'
213
+ @t.assert_binding_stack [@o, @obj, 79]
214
+ end
215
+
216
+ it 'should cd back to top-level and then into another ivar using cd /@ivar/ syntax' do
217
+ @t.eval '@z = 20', 'cd @obj/@x/', 'cd /@z'
218
+ @t.assert_binding_stack [@o, 20]
219
+ end
220
+
221
+ it 'should start a session on TOPLEVEL_BINDING with cd ::' do
222
+ @t.eval 'cd ::'
223
+ @t.eval('self').should == TOPLEVEL_BINDING.eval('self')
224
+ end
225
+
226
+ it 'should cd into complex input (with spaces)' do
227
+ def @o.hello(x, y, z)
228
+ :mon_ouie
229
+ end
230
+
231
+ @t.eval 'cd hello 1, 2, 3'
232
+ @t.eval('self').should == :mon_ouie
233
+ end
234
+
235
+ it 'should not cd into complex input when it encounters an exception' do
236
+ proc {
237
+ @t.eval 'cd 1/2/swoop_a_doop/3'
238
+ }.should.raise(Pry::CommandError)
239
+
240
+ @t.assert_binding_stack [@o]
241
+ end
242
+
243
+ # Regression test for ticket #516.
244
+ # FIXME: This is actually broken.
245
+ # it 'should be able to cd into the Object BasicObject' do
246
+ # proc {
247
+ # @t.eval 'cd BasicObject.new'
248
+ # }.should.not.raise
249
+ # end
250
+ end