pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG +63 -2
- data/CONTRIBUTORS +43 -25
- data/Gemfile +7 -0
- data/Guardfile +62 -0
- data/README.markdown +4 -4
- data/Rakefile +34 -35
- data/lib/pry.rb +107 -54
- data/lib/pry/cli.rb +34 -11
- data/lib/pry/code.rb +165 -182
- data/lib/pry/code/code_range.rb +70 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +153 -0
- data/lib/pry/command.rb +160 -22
- data/lib/pry/command_set.rb +37 -26
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +53 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +78 -0
- data/lib/pry/commands/cat/file_formatter.rb +84 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +30 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/deprecated_commands.rb +2 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +206 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
- data/lib/pry/commands/edit/method_patcher.rb +122 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +24 -0
- data/lib/pry/commands/find_method.rb +199 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +29 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +95 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +161 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +51 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/ls.rb +339 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +69 -0
- data/lib/pry/commands/pry_backtrace.rb +26 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +39 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +56 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +43 -0
- data/lib/pry/commands/shell_mode.rb +27 -0
- data/lib/pry/commands/show_doc.rb +78 -0
- data/lib/pry/commands/show_info.rb +139 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +37 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +20 -0
- data/lib/pry/commands/whereami.rb +114 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/completion.rb +120 -46
- data/lib/pry/config.rb +11 -0
- data/lib/pry/core_extensions.rb +30 -19
- data/lib/pry/editor.rb +129 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +89 -119
- data/lib/pry/helpers/command_helpers.rb +7 -122
- data/lib/pry/helpers/table.rb +100 -0
- data/lib/pry/helpers/text.rb +4 -4
- data/lib/pry/history_array.rb +5 -0
- data/lib/pry/hooks.rb +1 -3
- data/lib/pry/indent.rb +104 -30
- data/lib/pry/method.rb +66 -22
- data/lib/pry/module_candidate.rb +26 -15
- data/lib/pry/pager.rb +70 -0
- data/lib/pry/plugins.rb +1 -2
- data/lib/pry/pry_class.rb +63 -22
- data/lib/pry/pry_instance.rb +58 -37
- data/lib/pry/rubygem.rb +74 -0
- data/lib/pry/terminal_info.rb +43 -0
- data/lib/pry/test/helper.rb +185 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +58 -24
- data/pry.gemspec +21 -37
- data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
- data/spec/code_object_spec.rb +277 -0
- data/{test/test_code.rb → spec/code_spec.rb} +19 -1
- data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
- data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
- data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
- data/{test/test_command.rb → spec/command_spec.rb} +250 -149
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +19 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +727 -0
- data/spec/commands/exit_all_spec.rb +34 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +34 -0
- data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +75 -0
- data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
- data/spec/commands/hist_spec.rb +181 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +177 -0
- data/spec/commands/play_spec.rb +140 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +378 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +597 -0
- data/spec/commands/whereami_spec.rb +154 -0
- data/spec/completion_spec.rb +233 -0
- data/spec/control_d_handler_spec.rb +58 -0
- data/spec/editor_spec.rb +79 -0
- data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
- data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
- data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
- data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/{test → spec/fixtures}/testrc +0 -0
- data/{test → spec/fixtures}/testrcbad +0 -0
- data/spec/helper.rb +34 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +43 -0
- data/spec/helpers/table_spec.rb +83 -0
- data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
- data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
- data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
- data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
- data/{test/test_method.rb → spec/method_spec.rb} +65 -1
- data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
- data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
- data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
- data/spec/pry_output_spec.rb +95 -0
- data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
- data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
- data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
- data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
- metadata +239 -115
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/test/helper.rb +0 -223
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/test_cd.rb +0 -321
- data/test/test_default_commands/test_context.rb +0 -288
- data/test/test_default_commands/test_documentation.rb +0 -315
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_pry_output.rb +0 -41
@@ -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
|
+
eval_str = unindent(<<-STR)
|
10
|
+
def hello
|
11
|
+
puts :bing
|
12
|
+
STR
|
13
|
+
|
14
|
+
@t.process_command 'amend-line puts :blah', eval_str
|
15
|
+
|
16
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
24
|
+
def hello
|
25
|
+
puts :bing
|
26
|
+
puts :bang
|
27
|
+
STR
|
28
|
+
|
29
|
+
@t.process_command 'amend-line 1 def goodbye', eval_str
|
30
|
+
|
31
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
40
|
+
def hello
|
41
|
+
puts :bing
|
42
|
+
puts :bang
|
43
|
+
STR
|
44
|
+
|
45
|
+
@t.process_command 'amend-line 0 def goodbye', eval_str
|
46
|
+
|
47
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
56
|
+
def hello
|
57
|
+
puts :bing
|
58
|
+
puts :bang
|
59
|
+
STR
|
60
|
+
|
61
|
+
@t.process_command 'amend-line -1 puts :bink', eval_str
|
62
|
+
|
63
|
+
eval_str.should == unindent(<<-STR)
|
64
|
+
def hello
|
65
|
+
puts :bing
|
66
|
+
puts :bink
|
67
|
+
STR
|
68
|
+
|
69
|
+
@t.process_command 'amend-line -2 puts :bink', eval_str
|
70
|
+
|
71
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
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', eval_str
|
87
|
+
|
88
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
97
|
+
def hello
|
98
|
+
puts :bing
|
99
|
+
puts :bang
|
100
|
+
STR
|
101
|
+
|
102
|
+
@t.process_command 'amend-line puts "#{goodbye}"', eval_str
|
103
|
+
|
104
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
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', eval_str
|
133
|
+
|
134
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
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 !', eval_str
|
151
|
+
|
152
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
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 !', eval_str
|
170
|
+
|
171
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
179
|
+
def hello
|
180
|
+
puts :bing
|
181
|
+
puts :bang
|
182
|
+
puts :boast
|
183
|
+
puts :heart
|
184
|
+
STR
|
185
|
+
|
186
|
+
@t.process_command 'amend-line !', eval_str
|
187
|
+
|
188
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
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', eval_str
|
206
|
+
|
207
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
216
|
+
def hello
|
217
|
+
puts :bing
|
218
|
+
puts :bang
|
219
|
+
STR
|
220
|
+
|
221
|
+
@t.process_command 'amend-line 2 > puts :inserted', eval_str
|
222
|
+
|
223
|
+
eval_str.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
|
+
eval_str = unindent(<<-STR)
|
233
|
+
def hello
|
234
|
+
puts :bing
|
235
|
+
puts :bang
|
236
|
+
STR
|
237
|
+
|
238
|
+
@t.process_command 'amend-line 2..21 > puts :inserted', eval_str
|
239
|
+
|
240
|
+
eval_str.should == unindent(<<-STR)
|
241
|
+
def hello
|
242
|
+
puts :inserted
|
243
|
+
puts :bing
|
244
|
+
puts :bang
|
245
|
+
STR
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
eval_str = unindent(<<-STR)
|
10
|
+
def hello
|
11
|
+
puts :bing
|
12
|
+
STR
|
13
|
+
|
14
|
+
@t.process_command '!', eval_str
|
15
|
+
@t.last_output.should =~ /Input buffer cleared!/
|
16
|
+
|
17
|
+
eval_str.should == ''
|
18
|
+
end
|
19
|
+
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
|