pry 0.10.pre.1-java → 0.10.0.pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +126 -182
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- 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 +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -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 +23 -0
- data/lib/pry/commands/find_method.rb +193 -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 +32 -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 +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -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 +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -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 +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- 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/completion.rb +0 -221
- data/lib/pry/custom_completions.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/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- 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_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -1,432 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
if !mri18_and_no_real_source_location?
|
4
|
-
describe "show-source" do
|
5
|
-
before do
|
6
|
-
@str_output = StringIO.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should output a method\'s source' do
|
10
|
-
redirect_pry_io(InputTester.new("show-source sample_method", "exit-all"), @str_output) do
|
11
|
-
pry
|
12
|
-
end
|
13
|
-
|
14
|
-
@str_output.string.should =~ /def sample/
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should output help' do
|
18
|
-
mock_pry('show-source -h').should =~ /Usage: show-source/
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should output a method\'s source with line numbers' do
|
22
|
-
redirect_pry_io(InputTester.new("show-source -l sample_method", "exit-all"), @str_output) do
|
23
|
-
pry
|
24
|
-
end
|
25
|
-
|
26
|
-
@str_output.string.should =~ /\d+: def sample/
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should output a method\'s source with line numbers starting at 1' do
|
30
|
-
redirect_pry_io(InputTester.new("show-source -b sample_method", "exit-all"), @str_output) do
|
31
|
-
pry
|
32
|
-
end
|
33
|
-
|
34
|
-
@str_output.string.should =~ /1: def sample/
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should output a method\'s source if inside method without needing to use method name' do
|
38
|
-
$str_output = StringIO.new
|
39
|
-
|
40
|
-
o = Object.new
|
41
|
-
def o.sample
|
42
|
-
redirect_pry_io(InputTester.new("show-source", "exit-all"), $str_output) do
|
43
|
-
binding.pry
|
44
|
-
end
|
45
|
-
end
|
46
|
-
o.sample
|
47
|
-
|
48
|
-
$str_output.string.should =~ /def o.sample/
|
49
|
-
$str_output = nil
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do
|
53
|
-
$str_output = StringIO.new
|
54
|
-
|
55
|
-
o = Object.new
|
56
|
-
def o.sample
|
57
|
-
redirect_pry_io(InputTester.new("show-source -l", "exit-all"), $str_output) do
|
58
|
-
binding.pry
|
59
|
-
end
|
60
|
-
end
|
61
|
-
o.sample
|
62
|
-
|
63
|
-
$str_output.string.should =~ /\d+: def o.sample/
|
64
|
-
$str_output = nil
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should find methods even if there are spaces in the arguments" do
|
68
|
-
o = Object.new
|
69
|
-
def o.foo(*bars);
|
70
|
-
"Mr flibble"
|
71
|
-
self;
|
72
|
-
end
|
73
|
-
|
74
|
-
redirect_pry_io(InputTester.new("show-source o.foo('bar', 'baz bam').foo", "exit-all"), @str_output) do
|
75
|
-
binding.pry
|
76
|
-
end
|
77
|
-
|
78
|
-
@str_output.string.should =~ /Mr flibble/
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should find methods even if the object has an overridden method method" do
|
82
|
-
c = Class.new{
|
83
|
-
def method;
|
84
|
-
98
|
85
|
-
end
|
86
|
-
}
|
87
|
-
|
88
|
-
mock_pry(binding, "show-source c.new.method").should =~ /98/
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should find instance_methods even if the class has an override instance_method method" do
|
92
|
-
c = Class.new{
|
93
|
-
def method;
|
94
|
-
98
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.instance_method; 789; end
|
98
|
-
}
|
99
|
-
|
100
|
-
mock_pry(binding, "show-source c#method").should =~ /98/
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should find instance methods with -M" do
|
104
|
-
c = Class.new{ def moo; "ve over!"; end }
|
105
|
-
mock_pry(binding, "cd c","show-source -M moo").should =~ /ve over/
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should not find instance methods with -m" do
|
109
|
-
c = Class.new{ def moo; "ve over!"; end }
|
110
|
-
mock_pry(binding, "cd c", "show-source -m moo").should =~ /could not be found/
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should find normal methods with -m" do
|
114
|
-
c = Class.new{ def self.moo; "ve over!"; end }
|
115
|
-
mock_pry(binding, "cd c", "show-source -m moo").should =~ /ve over/
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should not find normal methods with -M" do
|
119
|
-
c = Class.new{ def self.moo; "ve over!"; end }
|
120
|
-
mock_pry(binding, "cd c", "show-source -M moo").should =~ /could not be found/
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should find normal methods with no -M or -m" do
|
124
|
-
c = Class.new{ def self.moo; "ve over!"; end }
|
125
|
-
mock_pry(binding, "cd c", "show-source moo").should =~ /ve over/
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should find instance methods with no -M or -m" do
|
129
|
-
c = Class.new{ def moo; "ve over!"; end }
|
130
|
-
mock_pry(binding, "cd c", "show-source moo").should =~ /ve over/
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should find super methods" do
|
134
|
-
class Foo
|
135
|
-
def foo(*bars)
|
136
|
-
:super_wibble
|
137
|
-
end
|
138
|
-
end
|
139
|
-
o = Foo.new
|
140
|
-
Object.remove_const(:Foo)
|
141
|
-
def o.foo(*bars)
|
142
|
-
:wibble
|
143
|
-
end
|
144
|
-
|
145
|
-
mock_pry(binding, "show-source --super o.foo").should =~ /:super_wibble/
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should not raise an exception when a non-extant super method is requested" do
|
149
|
-
o = Object.new
|
150
|
-
def o.foo(*bars); end
|
151
|
-
|
152
|
-
mock_pry(binding, "show-source --super o.foo").should =~ /'self.foo' has no super method/
|
153
|
-
end
|
154
|
-
|
155
|
-
# dynamically defined method source retrieval is only supported in
|
156
|
-
# 1.9 - where Method#source_location is native
|
157
|
-
if RUBY_VERSION =~ /1.9/
|
158
|
-
it 'should output a method\'s source for a method defined inside pry' do
|
159
|
-
redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
|
160
|
-
TOPLEVEL_BINDING.pry
|
161
|
-
end
|
162
|
-
|
163
|
-
@str_output.string.should =~ /def dyna_method/
|
164
|
-
Object.remove_method :dyna_method
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do
|
168
|
-
redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
|
169
|
-
TOPLEVEL_BINDING.pry
|
170
|
-
end
|
171
|
-
|
172
|
-
@str_output.string.should =~ /def dyna_method/
|
173
|
-
Object.remove_method :dyna_method
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'should output an instance method\'s source for a method defined inside pry' do
|
177
|
-
Object.remove_const :A if defined?(A)
|
178
|
-
redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-source A#yo"), @str_output) do
|
179
|
-
TOPLEVEL_BINDING.pry
|
180
|
-
end
|
181
|
-
|
182
|
-
@str_output.string.should =~ /def yo/
|
183
|
-
Object.remove_const :A
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'should output an instance method\'s source for a method defined inside pry using define_method' do
|
187
|
-
Object.remove_const :A if defined?(A)
|
188
|
-
redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "show-source A#yup"), @str_output) do
|
189
|
-
TOPLEVEL_BINDING.pry
|
190
|
-
end
|
191
|
-
|
192
|
-
@str_output.string.should =~ /define_method\(:yup\)/
|
193
|
-
Object.remove_const :A
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "on modules" do
|
198
|
-
before do
|
199
|
-
class ShowSourceTestClass
|
200
|
-
def alpha
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
module ShowSourceTestModule
|
205
|
-
def alpha
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
ShowSourceTestClassWeirdSyntax = Class.new do
|
210
|
-
def beta
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
ShowSourceTestModuleWeirdSyntax = Module.new do
|
215
|
-
def beta
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
after do
|
221
|
-
Object.remove_const :ShowSourceTestClass
|
222
|
-
Object.remove_const :ShowSourceTestClassWeirdSyntax
|
223
|
-
Object.remove_const :ShowSourceTestModule
|
224
|
-
Object.remove_const :ShowSourceTestModuleWeirdSyntax
|
225
|
-
end
|
226
|
-
|
227
|
-
describe "basic functionality, should find top-level module definitions" do
|
228
|
-
it 'should show source for a class' do
|
229
|
-
mock_pry("show-source ShowSourceTestClass").should =~ /class ShowSourceTest.*?def alpha/m
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should show source for a module' do
|
233
|
-
mock_pry("show-source ShowSourceTestModule").should =~ /module ShowSourceTestModule/
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'should show source for a class when Const = Class.new syntax is used' do
|
237
|
-
mock_pry("show-source ShowSourceTestClassWeirdSyntax").should =~ /ShowSourceTestClassWeirdSyntax = Class.new/
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'should show source for a module when Const = Module.new syntax is used' do
|
241
|
-
mock_pry("show-source ShowSourceTestModuleWeirdSyntax").should =~ /ShowSourceTestModuleWeirdSyntax = Module.new/
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
if !Pry::Helpers::BaseHelpers.mri_18?
|
246
|
-
describe "in REPL" do
|
247
|
-
it 'should find class defined in repl' do
|
248
|
-
mock_pry("class TobinaMyDog", "def woof", "end", "end", "show-source TobinaMyDog").should =~ /class TobinaMyDog/
|
249
|
-
Object.remove_const :TobinaMyDog
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'should lookup module name with respect to current context' do
|
255
|
-
constant_scope(:AlphaClass, :BetaClass) do
|
256
|
-
class BetaClass
|
257
|
-
def alpha
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
class AlphaClass
|
262
|
-
class BetaClass
|
263
|
-
def beta
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
redirect_pry_io(InputTester.new("show-source BetaClass", "exit-all"), out=StringIO.new) do
|
269
|
-
AlphaClass.pry
|
270
|
-
end
|
271
|
-
|
272
|
-
out.string.should =~ /def beta/
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'should lookup nested modules' do
|
277
|
-
constant_scope(:AlphaClass) do
|
278
|
-
class AlphaClass
|
279
|
-
class BetaClass
|
280
|
-
def beta
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
mock_pry("show-source AlphaClass::BetaClass").should =~ /class BetaClass/
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
# note that pry assumes a class is only monkey-patched at most
|
290
|
-
# ONCE per file, so will not find multiple monkeypatches in the
|
291
|
-
# SAME file.
|
292
|
-
describe "show-source -a" do
|
293
|
-
it 'should show the source for all monkeypatches defined in different files' do
|
294
|
-
class TestClassForShowSource
|
295
|
-
def beta
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
result = mock_pry("show-source TestClassForShowSource -a")
|
300
|
-
result.should =~ /def alpha/
|
301
|
-
result.should =~ /def beta/
|
302
|
-
end
|
303
|
-
|
304
|
-
it 'should show the source for a class_eval-based monkeypatch' do
|
305
|
-
TestClassForShowSourceClassEval.class_eval do
|
306
|
-
def class_eval_method
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
result = mock_pry("show-source TestClassForShowSourceClassEval -a")
|
311
|
-
result.should =~ /def class_eval_method/
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'should show the source for an instance_eval-based monkeypatch' do
|
315
|
-
TestClassForShowSourceInstanceEval.instance_eval do
|
316
|
-
def instance_eval_method
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
result = mock_pry("show-source TestClassForShowSourceInstanceEval -a")
|
321
|
-
result.should =~ /def instance_eval_method/
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
describe "when show-source is invoked without a method or class argument" do
|
326
|
-
before do
|
327
|
-
module TestHost
|
328
|
-
class M
|
329
|
-
def alpha; end
|
330
|
-
def beta; end
|
331
|
-
end
|
332
|
-
|
333
|
-
module C
|
334
|
-
end
|
335
|
-
|
336
|
-
module D
|
337
|
-
def self.invoked_in_method
|
338
|
-
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
339
|
-
Pry.start(binding)
|
340
|
-
end
|
341
|
-
out.string
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
after do
|
348
|
-
Object.remove_const(:TestHost)
|
349
|
-
end
|
350
|
-
|
351
|
-
describe "inside a module" do
|
352
|
-
it 'should display module source by default' do
|
353
|
-
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
354
|
-
Pry.start(TestHost::M)
|
355
|
-
end
|
356
|
-
|
357
|
-
out.string.should =~ /class M/
|
358
|
-
out.string.should =~ /def alpha/
|
359
|
-
out.string.should =~ /def beta/
|
360
|
-
end
|
361
|
-
|
362
|
-
it 'should be unable to find module source if no methods defined' do
|
363
|
-
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
364
|
-
Pry.start(TestHost::C)
|
365
|
-
end
|
366
|
-
|
367
|
-
out.string.should.should =~ /Cannot find a definition for/
|
368
|
-
end
|
369
|
-
|
370
|
-
it 'should display method code (rather than class) if Pry started inside method binding' do
|
371
|
-
string = TestHost::D.invoked_in_method
|
372
|
-
string.should =~ /invoked_in_method/
|
373
|
-
string.should.not =~ /module D/
|
374
|
-
end
|
375
|
-
|
376
|
-
it 'should display class source when inside instance' do
|
377
|
-
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
378
|
-
Pry.start(TestHost::M.new)
|
379
|
-
end
|
380
|
-
|
381
|
-
out.string.should =~ /class M/
|
382
|
-
out.string.should =~ /def alpha/
|
383
|
-
out.string.should =~ /def beta/
|
384
|
-
end
|
385
|
-
|
386
|
-
it 'should allow options to be passed' do
|
387
|
-
redirect_pry_io(InputTester.new("show-source -b", "exit-all"), out = StringIO.new) do
|
388
|
-
Pry.start(TestHost::M)
|
389
|
-
end
|
390
|
-
|
391
|
-
out.string.should =~ /\d:\s*class M/
|
392
|
-
out.string.should =~ /\d:\s*def alpha/
|
393
|
-
out.string.should =~ /\d:\s*def beta/
|
394
|
-
end
|
395
|
-
|
396
|
-
describe "should skip over broken modules" do
|
397
|
-
before do
|
398
|
-
module BabyDuck
|
399
|
-
|
400
|
-
module Muesli
|
401
|
-
binding.eval("def a; end", "dummy.rb", 1)
|
402
|
-
binding.eval("def b; end", "dummy.rb", 2)
|
403
|
-
binding.eval("def c; end", "dummy.rb", 3)
|
404
|
-
end
|
405
|
-
|
406
|
-
module Muesli
|
407
|
-
def d; end
|
408
|
-
def e; end
|
409
|
-
end
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
after do
|
414
|
-
Object.remove_const(:BabyDuck)
|
415
|
-
end
|
416
|
-
|
417
|
-
it 'should return source for first valid module' do
|
418
|
-
redirect_pry_io(InputTester.new("show-source BabyDuck::Muesli"), out = StringIO.new) do
|
419
|
-
Pry.start
|
420
|
-
end
|
421
|
-
|
422
|
-
out.string.should =~ /def d; end/
|
423
|
-
out.string.should.not =~ /def a; end/
|
424
|
-
end
|
425
|
-
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry.config.exception_whitelist" do
|
4
|
-
before do
|
5
|
-
@str_output = StringIO.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should rescue all exceptions NOT specified on whitelist' do
|
9
|
-
Pry.config.exception_whitelist.include?(NameError).should == false
|
10
|
-
lambda { Pry.start(self, :input => StringIO.new("raise NameError\nexit"), :output => @str_output) }.should.not.raise NameError
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should NOT rescue exceptions specified on whitelist' do
|
14
|
-
old_whitelist = Pry.config.exception_whitelist
|
15
|
-
Pry.config.exception_whitelist = [NameError]
|
16
|
-
lambda { Pry.start(self, :input => StringIO.new("raise NameError"), :output => @str_output) }.should.raise NameError
|
17
|
-
Pry.config.exception_whitelist = old_whitelist
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|