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
data/test/test_pry.rb
DELETED
@@ -1,463 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry do
|
4
|
-
before do
|
5
|
-
@str_output = StringIO.new
|
6
|
-
end
|
7
|
-
|
8
|
-
if RUBY_VERSION =~ /1.9/
|
9
|
-
describe "Exotic object support" do
|
10
|
-
# regression test for exotic object support
|
11
|
-
it "Should not error when return value is a BasicObject instance" do
|
12
|
-
|
13
|
-
lambda do
|
14
|
-
redirect_pry_io(InputTester.new("BasicObject.new", "exit-all"), StringIO.new) do
|
15
|
-
Pry.start
|
16
|
-
end
|
17
|
-
end.should.not.raise NoMethodError
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "Pry.binding_for" do
|
24
|
-
|
25
|
-
# regression test for burg's bug (see git history)
|
26
|
-
it "Should not error when object doesn't have a valid == method" do
|
27
|
-
o = Object.new
|
28
|
-
def o.==(other)
|
29
|
-
raise
|
30
|
-
end
|
31
|
-
|
32
|
-
lambda { Pry.binding_for(o) }.should.not.raise Exception
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "open a Pry session on an object" do
|
37
|
-
describe "rep" do
|
38
|
-
before do
|
39
|
-
class Hello
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
after do
|
44
|
-
Object.send(:remove_const, :Hello)
|
45
|
-
end
|
46
|
-
|
47
|
-
# bug fix for https://github.com/banister/pry/issues/93
|
48
|
-
it 'should not leak pry constants into Object namespace' do
|
49
|
-
input_string = "Command"
|
50
|
-
o = Object.new
|
51
|
-
pry_tester = Pry.new(:input => StringIO.new(input_string),
|
52
|
-
:output => @str_output,
|
53
|
-
:exception_handler => proc { |_, exception, _pry_| @excep = exception },
|
54
|
-
:print => proc {}
|
55
|
-
).rep(o)
|
56
|
-
|
57
|
-
@excep.is_a?(NameError).should == true
|
58
|
-
end
|
59
|
-
|
60
|
-
if defined?(BasicObject)
|
61
|
-
it 'should be able to operate inside the BasicObject class' do
|
62
|
-
$obj = nil
|
63
|
-
redirect_pry_io(InputTester.new(":foo", "$obj = _", "exit-all"), StringIO.new) do
|
64
|
-
BasicObject.pry
|
65
|
-
end
|
66
|
-
$obj.should == :foo
|
67
|
-
$obj = nil
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should set an ivar on an object' do
|
72
|
-
input_string = "@x = 10"
|
73
|
-
input = InputTester.new(input_string)
|
74
|
-
o = Object.new
|
75
|
-
|
76
|
-
pry_tester = Pry.new(:input => input, :output => Pry::NullOutput)
|
77
|
-
pry_tester.rep(o)
|
78
|
-
o.instance_variable_get(:@x).should == 10
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should display error and throw(:breakout) if Pry instance runs out of input' do
|
82
|
-
catch(:breakout) do
|
83
|
-
redirect_pry_io(StringIO.new(":nothing\n"), @str_output) do
|
84
|
-
Pry.new.repl
|
85
|
-
end
|
86
|
-
end
|
87
|
-
@str_output.string.should =~ /Error: Pry ran out of things to read/
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should make self evaluate to the receiver of the rep session' do
|
91
|
-
o = :john
|
92
|
-
|
93
|
-
pry_tester = Pry.new(:input => InputTester.new("self"), :output => @str_output)
|
94
|
-
pry_tester.rep(o)
|
95
|
-
@str_output.string.should =~ /:john/
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should work with multi-line input' do
|
99
|
-
o = Object.new
|
100
|
-
|
101
|
-
pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => @str_output)
|
102
|
-
pry_tester.rep(o)
|
103
|
-
@str_output.string.should =~ /5/
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should define a nested class under Hello and not on top-level or Pry' do
|
107
|
-
pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => Pry::NullOutput)
|
108
|
-
pry_tester.rep(Hello)
|
109
|
-
Hello.const_defined?(:Nested).should == true
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should suppress output if input ends in a ";" and is an Exception object (single line)' do
|
113
|
-
o = Object.new
|
114
|
-
|
115
|
-
pry_tester = Pry.new(:input => InputTester.new("Exception.new;"), :output => @str_output)
|
116
|
-
pry_tester.rep(o)
|
117
|
-
@str_output.string.should == ""
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should suppress output if input ends in a ";" (single line)' do
|
121
|
-
o = Object.new
|
122
|
-
|
123
|
-
pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => @str_output)
|
124
|
-
pry_tester.rep(o)
|
125
|
-
@str_output.string.should == ""
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should suppress output if input ends in a ";" (multi-line)' do
|
129
|
-
o = Object.new
|
130
|
-
|
131
|
-
pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => @str_output)
|
132
|
-
pry_tester.rep(o)
|
133
|
-
@str_output.string.should == ""
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'should be able to evaluate exceptions normally' do
|
137
|
-
o = Exception.new
|
138
|
-
|
139
|
-
was_called = false
|
140
|
-
pry_tester = Pry.new(:input => InputTester.new("self"),
|
141
|
-
:output => @str_output,
|
142
|
-
:exception_handler => proc { was_called = true })
|
143
|
-
|
144
|
-
pry_tester.rep(o)
|
145
|
-
was_called.should == false
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should notice when exceptions are raised' do
|
149
|
-
o = Exception.new
|
150
|
-
|
151
|
-
was_called = false
|
152
|
-
pry_tester = Pry.new(:input => InputTester.new("raise self"),
|
153
|
-
:output => @str_output,
|
154
|
-
:exception_handler => proc { was_called = true })
|
155
|
-
|
156
|
-
pry_tester.rep(o)
|
157
|
-
was_called.should == true
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'should not try to catch intended exceptions' do
|
161
|
-
lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
|
162
|
-
# SIGTERM
|
163
|
-
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "repl" do
|
168
|
-
describe "basic functionality" do
|
169
|
-
it 'should set an ivar on an object and exit the repl' do
|
170
|
-
input_strings = ["@x = 10", "exit-all"]
|
171
|
-
input = InputTester.new(*input_strings)
|
172
|
-
|
173
|
-
o = Object.new
|
174
|
-
|
175
|
-
pry_tester = Pry.start(o, :input => input, :output => Pry::NullOutput)
|
176
|
-
|
177
|
-
o.instance_variable_get(:@x).should == 10
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "complete_expression?" do
|
182
|
-
it "should not mutate the input!" do
|
183
|
-
clean = "puts <<-FOO\nhi\nFOO\n"
|
184
|
-
a = clean.dup
|
185
|
-
Pry::Code.complete_expression?(a)
|
186
|
-
a.should == clean
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
describe "history arrays" do
|
191
|
-
it 'sets _ to the last result' do
|
192
|
-
res = []
|
193
|
-
input = InputTester.new *[":foo", "self << _", "42", "self << _"]
|
194
|
-
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
195
|
-
pry.repl(res)
|
196
|
-
|
197
|
-
res.should == [:foo, 42]
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'sets out to an array with the result' do
|
201
|
-
res = {}
|
202
|
-
input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
|
203
|
-
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
204
|
-
pry.repl(res)
|
205
|
-
|
206
|
-
res[:res].should.be.kind_of Pry::HistoryArray
|
207
|
-
res[:res][1..2].should == [:foo, 42]
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'sets _in_ to an array with the entered lines' do
|
211
|
-
res = {}
|
212
|
-
input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
|
213
|
-
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
214
|
-
pry.repl(res)
|
215
|
-
|
216
|
-
res[:res].should.be.kind_of Pry::HistoryArray
|
217
|
-
res[:res][1..2].should == [":foo\n", "42\n"]
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'uses 100 as the size of _in_ and _out_' do
|
221
|
-
res = []
|
222
|
-
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
223
|
-
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
224
|
-
pry.repl(res)
|
225
|
-
|
226
|
-
res.should == [100, 100]
|
227
|
-
end
|
228
|
-
|
229
|
-
it 'can change the size of the history arrays' do
|
230
|
-
res = []
|
231
|
-
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
232
|
-
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
233
|
-
:memory_size => 1000)
|
234
|
-
pry.repl(res)
|
235
|
-
|
236
|
-
res.should == [1000, 1000]
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'store exceptions' do
|
240
|
-
res = []
|
241
|
-
input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
|
242
|
-
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
243
|
-
:memory_size => 1000)
|
244
|
-
pry.repl(res)
|
245
|
-
|
246
|
-
res.first.should == "foo!\n"
|
247
|
-
res.last.should.be.kind_of NoMethodError
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe "last_result" do
|
252
|
-
it "should be set to the most recent value" do
|
253
|
-
mock_pry("2", "_ + 82").should =~ /84/
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should be set to the result of a command with :keep_retval" do
|
257
|
-
mock_pry("Pry::Commands.block_command '++', '', {:keep_retval => true} do |a| a.to_i + 1; end", '++ 86', '++ #{_}').should =~ /88/
|
258
|
-
end
|
259
|
-
|
260
|
-
it "should be preserved over an empty line" do
|
261
|
-
mock_pry("2 + 2", " ", "\t", " ", "_ + 92").should =~ /96/
|
262
|
-
end
|
263
|
-
|
264
|
-
it "should be preserved when evalling a command without :keep_retval" do
|
265
|
-
mock_pry("2 + 2", "ls -l", "_ + 96").should =~ /100/
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
describe "test loading rc files" do
|
270
|
-
|
271
|
-
before do
|
272
|
-
Pry.instance_variable_set(:@initial_session, true)
|
273
|
-
end
|
274
|
-
|
275
|
-
after do
|
276
|
-
Pry::RC_FILES.clear
|
277
|
-
Pry.config.should_load_rc = false
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should run the rc file only once" do
|
281
|
-
Pry.config.should_load_rc = true
|
282
|
-
2.times { Pry::RC_FILES << File.expand_path("../testrc", __FILE__) }
|
283
|
-
|
284
|
-
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
285
|
-
TEST_RC.should == [0]
|
286
|
-
|
287
|
-
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
288
|
-
TEST_RC.should == [0]
|
289
|
-
|
290
|
-
Object.remove_const(:TEST_RC)
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should not load the pryrc if it cannot expand ENV[HOME]" do
|
294
|
-
old_home = ENV['HOME']
|
295
|
-
old_rc = Pry.config.should_load_rc
|
296
|
-
ENV['HOME'] = nil
|
297
|
-
Pry.config.should_load_rc = true
|
298
|
-
lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) }.should.not.raise
|
299
|
-
|
300
|
-
ENV['HOME'] = old_home
|
301
|
-
Pry.config.should_load_rc = old_rc
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
|
305
|
-
Pry.config.should_load_rc = false
|
306
|
-
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
307
|
-
Object.const_defined?(:TEST_RC).should == false
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should not load the rc file if #repl method invoked" do
|
311
|
-
Pry.config.should_load_rc = true
|
312
|
-
Pry.new(:input => StringIO.new("exit-all\n"), :output => Pry::NullOutput).repl(self)
|
313
|
-
Object.const_defined?(:TEST_RC).should == false
|
314
|
-
Pry.config.should_load_rc = false
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "that raise exceptions" do
|
318
|
-
before do
|
319
|
-
Pry::RC_FILES << File.expand_path("../testrcbad", __FILE__)
|
320
|
-
Pry.config.should_load_rc = true
|
321
|
-
|
322
|
-
putsed = nil
|
323
|
-
|
324
|
-
# YUCK! horrible hack to get round the fact that output is not configured
|
325
|
-
# at the point this message is printed.
|
326
|
-
(class << Pry; self; end).send(:define_method, :puts) { |str|
|
327
|
-
putsed = str
|
328
|
-
}
|
329
|
-
|
330
|
-
@doing_it = lambda{
|
331
|
-
Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => Pry::NullOutput)
|
332
|
-
putsed
|
333
|
-
}
|
334
|
-
end
|
335
|
-
|
336
|
-
after do
|
337
|
-
Object.remove_const(:TEST_BEFORE_RAISE)
|
338
|
-
Object.remove_const(:TEST_AFTER_RAISE)
|
339
|
-
(class << Pry; undef_method :puts; end)
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should not raise exceptions" do
|
343
|
-
@doing_it.should.not.raise
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should continue to run pry" do
|
347
|
-
@doing_it[]
|
348
|
-
Object.const_defined?(:TEST_BEFORE_RAISE).should == true
|
349
|
-
Object.const_defined?(:TEST_AFTER_RAISE).should == true
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should output an error" do
|
353
|
-
@doing_it[].should =~ /Error loading #{File.expand_path("../testrcbad", __FILE__)}: messin with ya/
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
describe "nesting" do
|
359
|
-
after do
|
360
|
-
Pry.reset_defaults
|
361
|
-
Pry.color = false
|
362
|
-
end
|
363
|
-
|
364
|
-
it 'should nest properly' do
|
365
|
-
Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
|
366
|
-
|
367
|
-
Pry.output = @str_output
|
368
|
-
|
369
|
-
o = Object.new
|
370
|
-
|
371
|
-
pry_tester = o.pry
|
372
|
-
@str_output.string.should =~ /nest:3/
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
describe "defining methods" do
|
377
|
-
it 'should define a method on the singleton class of an object when performing "def meth;end" inside the object' do
|
378
|
-
[Object.new, {}, []].each do |val|
|
379
|
-
str_input = StringIO.new("def hello;end")
|
380
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
381
|
-
|
382
|
-
val.methods(false).map(&:to_sym).include?(:hello).should == true
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
it 'should define an instance method on the module when performing "def meth;end" inside the module' do
|
387
|
-
str_input = StringIO.new("def hello;end")
|
388
|
-
hello = Module.new
|
389
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
390
|
-
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
391
|
-
end
|
392
|
-
|
393
|
-
it 'should define an instance method on the class when performing "def meth;end" inside the class' do
|
394
|
-
str_input = StringIO.new("def hello;end")
|
395
|
-
hello = Class.new
|
396
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
397
|
-
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
398
|
-
end
|
399
|
-
|
400
|
-
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
|
401
|
-
# should include float in here, but test fails for some reason
|
402
|
-
# on 1.8.7, no idea why!
|
403
|
-
[:test, 0, true, false, nil].each do |val|
|
404
|
-
str_input = StringIO.new("def hello;end")
|
405
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
406
|
-
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
407
|
-
end
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
describe "Object#pry" do
|
412
|
-
|
413
|
-
after do
|
414
|
-
Pry.reset_defaults
|
415
|
-
Pry.color = false
|
416
|
-
end
|
417
|
-
|
418
|
-
it "should start a pry session on the receiver (first form)" do
|
419
|
-
Pry.input = InputTester.new("self", "exit-all")
|
420
|
-
|
421
|
-
str_output = StringIO.new
|
422
|
-
Pry.output = str_output
|
423
|
-
|
424
|
-
20.pry
|
425
|
-
|
426
|
-
str_output.string.should =~ /20/
|
427
|
-
end
|
428
|
-
|
429
|
-
it "should start a pry session on the receiver (second form)" do
|
430
|
-
Pry.input = InputTester.new("self", "exit-all")
|
431
|
-
|
432
|
-
str_output = StringIO.new
|
433
|
-
Pry.output = str_output
|
434
|
-
|
435
|
-
pry 20
|
436
|
-
|
437
|
-
str_output.string.should =~ /20/
|
438
|
-
end
|
439
|
-
|
440
|
-
it "should raise if more than two arguments are passed to Object#pry" do
|
441
|
-
lambda { pry(20, :quiet, :input => Readline) }.should.raise ArgumentError
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
|
-
describe "Pry.binding_for" do
|
446
|
-
it 'should return TOPLEVEL_BINDING if parameter self is main' do
|
447
|
-
_main_ = lambda { TOPLEVEL_BINDING.eval('self') }
|
448
|
-
Pry.binding_for(_main_.call).is_a?(Binding).should == true
|
449
|
-
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
450
|
-
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
451
|
-
end
|
452
|
-
end
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
describe 'setting custom options' do
|
457
|
-
it 'should not raise for unrecognized options' do
|
458
|
-
should.not.raise?(NoMethodError) {
|
459
|
-
instance = Pry.new(:custom_option => 'custom value')
|
460
|
-
}
|
461
|
-
end
|
462
|
-
end
|
463
|
-
end
|