pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32
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 +122 -183
- 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,511 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry::DefaultCommands::Introspection" do
|
4
|
-
describe "edit" do
|
5
|
-
before do
|
6
|
-
@old_editor = Pry.config.editor
|
7
|
-
@file = nil; @line = nil; @contents = nil
|
8
|
-
Pry.config.editor = lambda do |file, line|
|
9
|
-
@file = file; @line = line; @contents = File.read(@file)
|
10
|
-
nil
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
after do
|
15
|
-
Pry.config.editor = @old_editor
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "with FILE" do
|
19
|
-
it "should invoke Pry.config.editor with absolutified filenames" do
|
20
|
-
mock_pry("edit foo.rb")
|
21
|
-
@file.should == File.expand_path("foo.rb")
|
22
|
-
mock_pry("edit /tmp/bar.rb")
|
23
|
-
@file.should == "/tmp/bar.rb"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should guess the line number from a colon" do
|
27
|
-
mock_pry("edit /tmp/foo.rb:10")
|
28
|
-
@line.should == 10
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should use the line number from -l" do
|
32
|
-
mock_pry("edit -l 10 /tmp/foo.rb")
|
33
|
-
@line.should == 10
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should not delete the file!" do
|
37
|
-
mock_pry("edit Rakefile")
|
38
|
-
File.exist?(@file).should == true
|
39
|
-
end
|
40
|
-
|
41
|
-
describe do
|
42
|
-
before do
|
43
|
-
@rand = rand
|
44
|
-
Pry.config.editor = lambda { |file, line|
|
45
|
-
File.open(file, 'w') { |f| f << "$rand = #{@rand.inspect}" }
|
46
|
-
nil
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should reload the file if it is a ruby file" do
|
51
|
-
tf = Tempfile.new(["pry", ".rb"])
|
52
|
-
path = tf.path
|
53
|
-
|
54
|
-
mock_pry("edit #{path}", "$rand").should =~ /#{@rand}/
|
55
|
-
|
56
|
-
tf.close(true)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should not reload the file if it is not a ruby file" do
|
60
|
-
tf = Tempfile.new(["pry", ".py"])
|
61
|
-
path = tf.path
|
62
|
-
|
63
|
-
mock_pry("edit #{path}", "$rand").should.not =~ /#{@rand}/
|
64
|
-
|
65
|
-
tf.close(true)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not reload a ruby file if -n is given" do
|
69
|
-
tf = Tempfile.new(["pry", ".rb"])
|
70
|
-
path = tf.path
|
71
|
-
|
72
|
-
mock_pry("edit -n #{path}", "$rand").should.not =~ /#{@rand}/
|
73
|
-
|
74
|
-
tf.close(true)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should reload a non-ruby file if -r is given" do
|
78
|
-
tf = Tempfile.new(["pry", ".pryrc"])
|
79
|
-
path = tf.path
|
80
|
-
|
81
|
-
mock_pry("edit -r #{path}", "$rand").should =~ /#{@rand}/
|
82
|
-
|
83
|
-
tf.close(true)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe do
|
88
|
-
before do
|
89
|
-
@reloading = nil
|
90
|
-
Pry.config.editor = lambda do |file, line, reloading|
|
91
|
-
@file = file; @line = line; @reloading = reloading
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should pass the editor a reloading arg" do
|
97
|
-
mock_pry("edit foo.rb")
|
98
|
-
@reloading.should == true
|
99
|
-
mock_pry("edit -n foo.rb")
|
100
|
-
@reloading.should == false
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "with --ex" do
|
106
|
-
before do
|
107
|
-
@tf = Tempfile.new(["pry", ".rb"])
|
108
|
-
@path = @tf.path
|
109
|
-
@tf << "1\n2\nraise RuntimeError"
|
110
|
-
@tf.flush
|
111
|
-
end
|
112
|
-
after do
|
113
|
-
@tf.close(true)
|
114
|
-
File.unlink("#{@path}c") if File.exists?("#{@path}c") #rbx
|
115
|
-
end
|
116
|
-
it "should open the correct file" do
|
117
|
-
mock_pry("require #{@path.inspect}", "edit --ex")
|
118
|
-
|
119
|
-
@file.should == @path
|
120
|
-
@line.should == 3
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should reload the file" do
|
124
|
-
Pry.config.editor = lambda {|file, line|
|
125
|
-
File.open(file, 'w'){|f| f << "FOO = 'BAR'" }
|
126
|
-
nil
|
127
|
-
}
|
128
|
-
|
129
|
-
mock_pry("require #{@path.inspect}", "edit --ex", "FOO").should =~ /BAR/
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should not reload the file if -n is passed" do
|
133
|
-
Pry.config.editor = lambda {|file, line|
|
134
|
-
File.open(file, 'w'){|f| f << "FOO2 = 'BAZ'" }
|
135
|
-
nil
|
136
|
-
}
|
137
|
-
|
138
|
-
mock_pry("require #{@path.inspect}", "edit -n --ex", "FOO2").should.not =~ /BAZ/
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "with --ex NUM" do
|
143
|
-
before do
|
144
|
-
Pry.config.editor = proc do |file, line|
|
145
|
-
@__ex_file__ = file
|
146
|
-
@__ex_line__ = line
|
147
|
-
nil
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should start editor on first level of backtrace when --ex used with no argument ' do
|
152
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex"), :output => StringIO.new)
|
153
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
154
|
-
pry_instance.rep(self)
|
155
|
-
@__ex_file__.should == "a"
|
156
|
-
@__ex_line__.should == 1
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should start editor on first level of backtrace when --ex 0 used ' do
|
160
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 0"), :output => StringIO.new)
|
161
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
162
|
-
pry_instance.rep(self)
|
163
|
-
@__ex_file__.should == "a"
|
164
|
-
@__ex_line__.should == 1
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should start editor on second level of backtrace when --ex 1 used' do
|
168
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 1"), :output => StringIO.new)
|
169
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
170
|
-
pry_instance.rep(self)
|
171
|
-
@__ex_file__.should == "b"
|
172
|
-
@__ex_line__.should == 2
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should start editor on third level of backtrace when --ex 2 used' do
|
176
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 2"), :output => StringIO.new)
|
177
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
178
|
-
pry_instance.rep(self)
|
179
|
-
@__ex_file__.should == "c"
|
180
|
-
@__ex_line__.should == 3
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'should display error message when backtrace level is out of bounds (using --ex 4)' do
|
184
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 4"), :output => str_output = StringIO.new)
|
185
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
186
|
-
pry_instance.rep(self)
|
187
|
-
str_output.string.should =~ /Exception has no associated file/
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "without FILE" do
|
192
|
-
it "should edit the current expression if it's incomplete" do
|
193
|
-
mock_pry("def a", "edit")
|
194
|
-
@contents.should == "def a\n"
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should edit the previous expression if the current is empty" do
|
198
|
-
mock_pry("def a; 2; end", "edit")
|
199
|
-
@contents.should == "def a; 2; end\n"
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should use a blank file if -t is specified" do
|
203
|
-
mock_pry("def a; 5; end", "edit -t")
|
204
|
-
@contents.should == "\n"
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should use a blank file if -t is specified even half-way through an expression" do
|
208
|
-
mock_pry("def a;", "edit -t")
|
209
|
-
@contents.should == "\n"
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should position the cursor at the end of the expression" do
|
213
|
-
mock_pry("def a; 2;"," end", "edit")
|
214
|
-
@line.should == 2
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should evaluate the expression" do
|
218
|
-
Pry.config.editor = lambda {|file, line|
|
219
|
-
File.open(file, 'w'){|f| f << "'FOO'\n" }
|
220
|
-
nil
|
221
|
-
}
|
222
|
-
mock_pry("edit").should =~ /FOO/
|
223
|
-
end
|
224
|
-
it "should not evaluate the expression with -n" do
|
225
|
-
Pry.config.editor = lambda {|file, line|
|
226
|
-
File.open(file, 'w'){|f| f << "'FOO'\n" }
|
227
|
-
nil
|
228
|
-
}
|
229
|
-
mock_pry("edit -n").should.not =~ /FOO/
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe "with --in" do
|
234
|
-
it "should edit the nth line of _in_" do
|
235
|
-
mock_pry("10", "11", "edit --in -2")
|
236
|
-
@contents.should == "10\n"
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should edit the last line if no argument is given" do
|
240
|
-
mock_pry("10", "11", "edit --in")
|
241
|
-
@contents.should == "11\n"
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should edit a range of lines if a range is given" do
|
245
|
-
mock_pry("10", "11", "edit -i 1,2")
|
246
|
-
@contents.should == "10\n11\n"
|
247
|
-
end
|
248
|
-
|
249
|
-
it "should edit a multi-line expression as it occupies one line of _in_" do
|
250
|
-
mock_pry("class Fixnum", " def invert; -self; end", "end", "edit -i 1")
|
251
|
-
@contents.should == "class Fixnum\n def invert; -self; end\nend\n"
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should not work with a filename" do
|
255
|
-
mock_pry("edit ruby.rb -i").should =~ /Only one of --ex, --temp, --in and FILE may be specified/
|
256
|
-
end
|
257
|
-
|
258
|
-
it "should not work with nonsense" do
|
259
|
-
mock_pry("edit --in three").should =~ /Not a valid range: three/
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "edit-method" do
|
265
|
-
describe "on a method defined in a file" do
|
266
|
-
before do
|
267
|
-
@tempfile = Tempfile.new(['pry', '*.rb'])
|
268
|
-
@tempfile.puts <<-EOS
|
269
|
-
module A
|
270
|
-
def a
|
271
|
-
:yup
|
272
|
-
end
|
273
|
-
|
274
|
-
def b
|
275
|
-
:kinda
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
class X
|
280
|
-
include A
|
281
|
-
|
282
|
-
def self.x
|
283
|
-
:double_yup
|
284
|
-
end
|
285
|
-
|
286
|
-
def x
|
287
|
-
:nope
|
288
|
-
end
|
289
|
-
|
290
|
-
def b
|
291
|
-
super
|
292
|
-
end
|
293
|
-
alias c b
|
294
|
-
|
295
|
-
def y?
|
296
|
-
:because
|
297
|
-
end
|
298
|
-
end
|
299
|
-
EOS
|
300
|
-
@tempfile.flush
|
301
|
-
load @tempfile.path
|
302
|
-
end
|
303
|
-
|
304
|
-
after do
|
305
|
-
@tempfile.close(true)
|
306
|
-
end
|
307
|
-
|
308
|
-
describe 'without -p' do
|
309
|
-
before do
|
310
|
-
@old_editor = Pry.config.editor
|
311
|
-
@file, @line, @contents = nil, nil, nil
|
312
|
-
Pry.config.editor = lambda do |file, line|
|
313
|
-
@file = file; @line = line
|
314
|
-
nil
|
315
|
-
end
|
316
|
-
end
|
317
|
-
after do
|
318
|
-
Pry.config.editor = @old_editor
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should correctly find a class method" do
|
322
|
-
mock_pry("edit-method X.x")
|
323
|
-
@file.should == @tempfile.path
|
324
|
-
@line.should == 14
|
325
|
-
end
|
326
|
-
|
327
|
-
it "should correctly find an instance method" do
|
328
|
-
mock_pry("edit-method X#x")
|
329
|
-
@file.should == @tempfile.path
|
330
|
-
@line.should == 18
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should correctly find a method on an instance" do
|
334
|
-
mock_pry("x = X.new", "edit-method x.x")
|
335
|
-
@file.should == @tempfile.path
|
336
|
-
@line.should == 18
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should correctly find a method from a module" do
|
340
|
-
mock_pry("edit-method X#a")
|
341
|
-
@file.should == @tempfile.path
|
342
|
-
@line.should == 2
|
343
|
-
end
|
344
|
-
|
345
|
-
it "should correctly find an aliased method" do
|
346
|
-
mock_pry("edit-method X#c")
|
347
|
-
@file.should == @tempfile.path
|
348
|
-
@line.should == 22
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe 'with -p' do
|
353
|
-
before do
|
354
|
-
@old_editor = Pry.config.editor
|
355
|
-
Pry.config.editor = lambda do |file, line|
|
356
|
-
lines = File.read(file).lines.to_a
|
357
|
-
lines[1] = ":maybe\n"
|
358
|
-
File.open(file, 'w') do |f|
|
359
|
-
f.write(lines.join)
|
360
|
-
end
|
361
|
-
nil
|
362
|
-
end
|
363
|
-
end
|
364
|
-
after do
|
365
|
-
Pry.config.editor = @old_editor
|
366
|
-
end
|
367
|
-
|
368
|
-
it "should successfully replace a class method" do
|
369
|
-
mock_pry("edit-method -p X.x")
|
370
|
-
|
371
|
-
class << X
|
372
|
-
X.method(:x).owner.should == self
|
373
|
-
end
|
374
|
-
X.method(:x).receiver.should == X
|
375
|
-
X.x.should == :maybe
|
376
|
-
end
|
377
|
-
|
378
|
-
it "should successfully replace an instance method" do
|
379
|
-
mock_pry("edit-method -p X#x")
|
380
|
-
|
381
|
-
X.instance_method(:x).owner.should == X
|
382
|
-
X.new.x.should == :maybe
|
383
|
-
end
|
384
|
-
|
385
|
-
it "should successfully replace a method on an instance" do
|
386
|
-
mock_pry("instance = X.new", "edit-method -p instance.x")
|
387
|
-
|
388
|
-
instance = X.new
|
389
|
-
instance.method(:x).owner.should == X
|
390
|
-
instance.x.should == :maybe
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should successfully replace a method from a module" do
|
394
|
-
mock_pry("edit-method -p X#a")
|
395
|
-
|
396
|
-
X.instance_method(:a).owner.should == A
|
397
|
-
X.new.a.should == :maybe
|
398
|
-
end
|
399
|
-
|
400
|
-
it "should successfully replace a method with a question mark" do
|
401
|
-
mock_pry("edit-method -p X#y?")
|
402
|
-
|
403
|
-
X.instance_method(:y?).owner.should == X
|
404
|
-
X.new.y?.should == :maybe
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
describe 'on an aliased method' do
|
409
|
-
before do
|
410
|
-
@old_editor = Pry.config.editor
|
411
|
-
Pry.config.editor = lambda do |file, line|
|
412
|
-
lines = File.read(file).lines.to_a
|
413
|
-
lines[1] = '"#{super}aa".to_sym' + "\n"
|
414
|
-
File.open(file, 'w') do |f|
|
415
|
-
f.write(lines.join)
|
416
|
-
end
|
417
|
-
nil
|
418
|
-
end
|
419
|
-
end
|
420
|
-
after do
|
421
|
-
Pry.config.editor = @old_editor
|
422
|
-
end
|
423
|
-
|
424
|
-
it "should change the alias, but not the original, without breaking super" do
|
425
|
-
mock_pry("edit-method -p X#c")
|
426
|
-
|
427
|
-
Pry::Method.from_str("X#c").alias?.should == true
|
428
|
-
|
429
|
-
X.new.b.should == :kinda
|
430
|
-
X.new.c.should == :kindaaa
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
describe 'with three-arg editor' do
|
435
|
-
before do
|
436
|
-
@old_editor = Pry.config.editor
|
437
|
-
@file, @line, @reloading = nil, nil, nil
|
438
|
-
Pry.config.editor = lambda do |file, line, reloading|
|
439
|
-
@file = file; @line = line; @reloading = reloading
|
440
|
-
nil
|
441
|
-
end
|
442
|
-
end
|
443
|
-
after do
|
444
|
-
Pry.config.editor = @old_editor
|
445
|
-
end
|
446
|
-
|
447
|
-
it "should pass the editor a reloading arg" do
|
448
|
-
mock_pry('edit-method X.x')
|
449
|
-
@reloading.should == true
|
450
|
-
mock_pry('edit-method -n X.x')
|
451
|
-
@reloading.should == false
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
# show-command only works in implementations that support Proc#source_location
|
459
|
-
if Proc.method_defined?(:source_location)
|
460
|
-
describe "show-command" do
|
461
|
-
before do
|
462
|
-
@str_output = StringIO.new
|
463
|
-
end
|
464
|
-
|
465
|
-
it 'should show source for an ordinary command' do
|
466
|
-
set = Pry::CommandSet.new do
|
467
|
-
import_from Pry::Commands, "show-command"
|
468
|
-
command "foo" do
|
469
|
-
:body_of_foo
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
redirect_pry_io(InputTester.new("show-command foo"), @str_output) do
|
474
|
-
Pry.new(:commands => set).rep
|
475
|
-
end
|
476
|
-
|
477
|
-
@str_output.string.should =~ /:body_of_foo/
|
478
|
-
end
|
479
|
-
|
480
|
-
it 'should show source for a command with spaces in its name' do
|
481
|
-
set = Pry::CommandSet.new do
|
482
|
-
import_from Pry::Commands, "show-command"
|
483
|
-
command "foo bar" do
|
484
|
-
:body_of_foo_bar
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
redirect_pry_io(InputTester.new("show-command \"foo bar\""), @str_output) do
|
489
|
-
Pry.new(:commands => set).rep
|
490
|
-
end
|
491
|
-
|
492
|
-
@str_output.string.should =~ /:body_of_foo_bar/
|
493
|
-
end
|
494
|
-
|
495
|
-
it 'should show source for a command by listing name' do
|
496
|
-
set = Pry::CommandSet.new do
|
497
|
-
import_from Pry::Commands, "show-command"
|
498
|
-
command /foo(.*)/, "", :listing => "bar" do
|
499
|
-
:body_of_foo_regex
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
redirect_pry_io(InputTester.new("show-command bar"), @str_output) do
|
504
|
-
Pry.new(:commands => set).rep
|
505
|
-
end
|
506
|
-
|
507
|
-
@str_output.string.should =~ /:body_of_foo_regex/
|
508
|
-
end
|
509
|
-
end
|
510
|
-
end
|
511
|
-
end
|