pry 0.9.12.2 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1141 -0
- data/LICENSE +2 -2
- data/README.md +466 -0
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +97 -92
- data/lib/pry/code/code_file.rb +114 -0
- data/lib/pry/code/code_range.rb +7 -4
- data/lib/pry/code/loc.rb +27 -14
- data/lib/pry/code.rb +62 -90
- data/lib/pry/code_object.rb +83 -39
- data/lib/pry/color_printer.rb +66 -0
- data/lib/pry/command.rb +202 -371
- data/lib/pry/command_set.rb +151 -133
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +85 -73
- data/lib/pry/commands/cat/file_formatter.rb +56 -63
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +64 -47
- data/lib/pry/commands/cd.rb +42 -26
- data/lib/pry/commands/change_inspector.rb +34 -0
- data/lib/pry/commands/change_prompt.rb +51 -0
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +33 -24
- data/lib/pry/commands/edit.rb +183 -167
- data/lib/pry/commands/exit.rb +40 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -17
- data/lib/pry/commands/find_method.rb +167 -167
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +153 -132
- data/lib/pry/commands/import_set.rb +20 -15
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +42 -0
- data/lib/pry/commands/ls/constants.rb +75 -0
- data/lib/pry/commands/ls/formatter.rb +55 -0
- data/lib/pry/commands/ls/globals.rb +50 -0
- data/lib/pry/commands/ls/grep.rb +23 -0
- data/lib/pry/commands/ls/instance_vars.rb +40 -0
- data/lib/pry/commands/ls/interrogatable.rb +24 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +55 -0
- data/lib/pry/commands/ls/local_names.rb +37 -0
- data/lib/pry/commands/ls/local_vars.rb +47 -0
- data/lib/pry/commands/ls/ls_entity.rb +65 -0
- data/lib/pry/commands/ls/methods.rb +55 -0
- data/lib/pry/commands/ls/methods_helper.rb +50 -0
- data/lib/pry/commands/ls/self_methods.rb +34 -0
- data/lib/pry/commands/ls.rb +100 -303
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -49
- data/lib/pry/commands/pry_backtrace.rb +22 -18
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +33 -27
- data/lib/pry/commands/reload_code.rb +57 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -38
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +66 -34
- data/lib/pry/commands/shell_mode.rb +22 -20
- data/lib/pry/commands/show_doc.rb +80 -65
- data/lib/pry/commands/show_info.rb +193 -159
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +113 -33
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +21 -13
- data/lib/pry/commands/watch_expression/expression.rb +43 -0
- data/lib/pry/commands/watch_expression.rb +110 -0
- data/lib/pry/commands/whereami.rb +157 -134
- data/lib/pry/commands/wtf.rb +78 -40
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +290 -220
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +50 -27
- data/lib/pry/editor.rb +130 -102
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +73 -0
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +22 -151
- data/lib/pry/helpers/command_helpers.rb +55 -63
- data/lib/pry/helpers/documentation_helpers.rb +21 -13
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -86
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +101 -70
- data/lib/pry/hooks.rb +67 -137
- data/lib/pry/indent.rb +79 -73
- data/lib/pry/input_completer.rb +283 -0
- data/lib/pry/input_lock.rb +129 -0
- data/lib/pry/inspector.rb +39 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +51 -42
- data/lib/pry/method/weird_method_locator.rb +80 -44
- data/lib/pry/method.rb +225 -176
- data/lib/pry/object_path.rb +91 -0
- data/lib/pry/output.rb +136 -0
- data/lib/pry/pager.rb +227 -68
- data/lib/pry/prompt.rb +214 -0
- data/lib/pry/pry_class.rb +216 -289
- data/lib/pry/pry_instance.rb +438 -500
- data/lib/pry/repl.rb +256 -0
- data/lib/pry/repl_file_loader.rb +34 -35
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +36 -43
- data/lib/pry/wrapped_module.rb +102 -103
- data/lib/pry.rb +135 -261
- metadata +94 -283
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -21
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -9
- data/Guardfile +0 -62
- data/README.markdown +0 -400
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -29
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -51
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/completion.rb +0 -304
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/history_array.rb +0 -116
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_method.rb +0 -13
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -74
- data/lib/pry/terminal.rb +0 -78
- data/lib/pry/test/helper.rb +0 -185
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -30
- data/spec/Procfile +0 -3
- data/spec/cli_spec.rb +0 -78
- data/spec/code_object_spec.rb +0 -277
- data/spec/code_spec.rb +0 -219
- data/spec/command_helpers_spec.rb +0 -29
- data/spec/command_integration_spec.rb +0 -644
- data/spec/command_set_spec.rb +0 -627
- data/spec/command_spec.rb +0 -821
- data/spec/commands/amend_line_spec.rb +0 -247
- data/spec/commands/bang_spec.rb +0 -19
- data/spec/commands/cat_spec.rb +0 -164
- data/spec/commands/cd_spec.rb +0 -250
- data/spec/commands/disable_pry_spec.rb +0 -25
- data/spec/commands/edit_spec.rb +0 -727
- data/spec/commands/exit_all_spec.rb +0 -34
- data/spec/commands/exit_program_spec.rb +0 -19
- data/spec/commands/exit_spec.rb +0 -34
- data/spec/commands/find_method_spec.rb +0 -70
- data/spec/commands/gem_list_spec.rb +0 -26
- data/spec/commands/gist_spec.rb +0 -79
- data/spec/commands/help_spec.rb +0 -56
- data/spec/commands/hist_spec.rb +0 -181
- data/spec/commands/jump_to_spec.rb +0 -15
- data/spec/commands/ls_spec.rb +0 -181
- data/spec/commands/play_spec.rb +0 -140
- data/spec/commands/raise_up_spec.rb +0 -56
- data/spec/commands/save_file_spec.rb +0 -177
- data/spec/commands/show_doc_spec.rb +0 -510
- data/spec/commands/show_input_spec.rb +0 -17
- data/spec/commands/show_source_spec.rb +0 -782
- data/spec/commands/whereami_spec.rb +0 -203
- data/spec/completion_spec.rb +0 -239
- data/spec/control_d_handler_spec.rb +0 -58
- data/spec/documentation_helper_spec.rb +0 -73
- data/spec/editor_spec.rb +0 -79
- data/spec/exception_whitelist_spec.rb +0 -21
- data/spec/fixtures/candidate_helper1.rb +0 -11
- data/spec/fixtures/candidate_helper2.rb +0 -8
- data/spec/fixtures/example.erb +0 -5
- data/spec/fixtures/example_nesting.rb +0 -33
- data/spec/fixtures/show_source_doc_examples.rb +0 -15
- data/spec/fixtures/testrc +0 -2
- data/spec/fixtures/testrcbad +0 -2
- data/spec/fixtures/whereami_helper.rb +0 -6
- data/spec/helper.rb +0 -34
- data/spec/helpers/bacon.rb +0 -86
- data/spec/helpers/mock_pry.rb +0 -43
- data/spec/helpers/table_spec.rb +0 -105
- data/spec/history_array_spec.rb +0 -67
- data/spec/hooks_spec.rb +0 -522
- data/spec/indent_spec.rb +0 -301
- data/spec/input_stack_spec.rb +0 -90
- data/spec/method_spec.rb +0 -482
- data/spec/prompt_spec.rb +0 -60
- data/spec/pry_defaults_spec.rb +0 -419
- data/spec/pry_history_spec.rb +0 -99
- data/spec/pry_output_spec.rb +0 -95
- data/spec/pry_spec.rb +0 -504
- data/spec/run_command_spec.rb +0 -25
- data/spec/sticky_locals_spec.rb +0 -157
- data/spec/syntax_checking_spec.rb +0 -81
- data/spec/wrapped_module_spec.rb +0 -261
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/spec/pry_spec.rb
DELETED
@@ -1,504 +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 'DISABLE_PRY' do
|
24
|
-
before do
|
25
|
-
ENV['DISABLE_PRY'] = 'true'
|
26
|
-
end
|
27
|
-
|
28
|
-
after do
|
29
|
-
ENV.delete 'DISABLE_PRY'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should not binding.pry' do
|
33
|
-
binding.pry.should == nil
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should not Pry.start' do
|
37
|
-
Pry.start.should == nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "Pry.critical_section" do
|
42
|
-
it "should prevent Pry being called" do
|
43
|
-
output = StringIO.new
|
44
|
-
Pry.output = output
|
45
|
-
Pry.critical_section do
|
46
|
-
Pry.start
|
47
|
-
end
|
48
|
-
output.string.should =~ /Pry started inside Pry/
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "Pry.binding_for" do
|
53
|
-
|
54
|
-
# regression test for burg's bug (see git history)
|
55
|
-
it "Should not error when object doesn't have a valid == method" do
|
56
|
-
o = Object.new
|
57
|
-
def o.==(other)
|
58
|
-
raise
|
59
|
-
end
|
60
|
-
|
61
|
-
lambda { Pry.binding_for(o) }.should.not.raise Exception
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not leak local variables" do
|
65
|
-
[Object.new, Array, 3].each do |obj|
|
66
|
-
Pry.binding_for(obj).eval("local_variables").should.be.empty
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "open a Pry session on an object" do
|
72
|
-
describe "rep" do
|
73
|
-
before do
|
74
|
-
class Hello
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
after do
|
79
|
-
Object.send(:remove_const, :Hello)
|
80
|
-
end
|
81
|
-
|
82
|
-
# bug fix for https://github.com/banister/pry/issues/93
|
83
|
-
it 'should not leak pry constants into Object namespace' do
|
84
|
-
input_string = "Command"
|
85
|
-
o = Object.new
|
86
|
-
pry_tester = Pry.new(:input => StringIO.new(input_string),
|
87
|
-
:output => @str_output,
|
88
|
-
:exception_handler => proc { |_, exception, _pry_| @excep = exception },
|
89
|
-
:print => proc {}
|
90
|
-
).rep(o)
|
91
|
-
|
92
|
-
@excep.is_a?(NameError).should == true
|
93
|
-
end
|
94
|
-
|
95
|
-
if defined?(BasicObject)
|
96
|
-
it 'should be able to operate inside the BasicObject class' do
|
97
|
-
redirect_pry_io(InputTester.new(":foo", "Pad.obj = _", "exit-all")) do
|
98
|
-
BasicObject.pry
|
99
|
-
end
|
100
|
-
|
101
|
-
Pad.obj.should == :foo
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should set an ivar on an object' do
|
106
|
-
input_string = "@x = 10"
|
107
|
-
input = InputTester.new(input_string)
|
108
|
-
o = Object.new
|
109
|
-
|
110
|
-
pry_tester = Pry.new(:input => input, :output => StringIO.new)
|
111
|
-
pry_tester.rep(o)
|
112
|
-
o.instance_variable_get(:@x).should == 10
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should display error if Pry instance runs out of input' do
|
116
|
-
redirect_pry_io(StringIO.new, @str_output) do
|
117
|
-
Pry.new.repl
|
118
|
-
end
|
119
|
-
@str_output.string.should =~ /Error: Pry ran out of things to read/
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should make self evaluate to the receiver of the rep session' do
|
123
|
-
o = :john
|
124
|
-
|
125
|
-
pry_tester = Pry.new(:input => InputTester.new("self"), :output => @str_output)
|
126
|
-
pry_tester.rep(o)
|
127
|
-
@str_output.string.should =~ /:john/
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should work with multi-line input' do
|
131
|
-
o = Object.new
|
132
|
-
|
133
|
-
pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => @str_output)
|
134
|
-
pry_tester.rep(o)
|
135
|
-
@str_output.string.should =~ /5/
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should define a nested class under Hello and not on top-level or Pry' do
|
139
|
-
pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => StringIO.new)
|
140
|
-
pry_tester.rep(Hello)
|
141
|
-
Hello.const_defined?(:Nested).should == true
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'should suppress output if input ends in a ";" and is an Exception object (single line)' do
|
145
|
-
o = Object.new
|
146
|
-
|
147
|
-
pry_tester = Pry.new(:input => InputTester.new("Exception.new;"), :output => @str_output)
|
148
|
-
pry_tester.rep(o)
|
149
|
-
@str_output.string.should == ""
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'should suppress output if input ends in a ";" (single line)' do
|
153
|
-
o = Object.new
|
154
|
-
|
155
|
-
pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => @str_output)
|
156
|
-
pry_tester.rep(o)
|
157
|
-
@str_output.string.should == ""
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'should suppress output if input ends in a ";" (multi-line)' do
|
161
|
-
o = Object.new
|
162
|
-
|
163
|
-
pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => @str_output)
|
164
|
-
pry_tester.rep(o)
|
165
|
-
@str_output.string.should == ""
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'should be able to evaluate exceptions normally' do
|
169
|
-
o = Exception.new
|
170
|
-
|
171
|
-
was_called = false
|
172
|
-
pry_tester = Pry.new(:input => InputTester.new("self"),
|
173
|
-
:output => @str_output,
|
174
|
-
:exception_handler => proc { was_called = true })
|
175
|
-
|
176
|
-
pry_tester.rep(o)
|
177
|
-
was_called.should == false
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'should notice when exceptions are raised' do
|
181
|
-
o = Exception.new
|
182
|
-
|
183
|
-
was_called = false
|
184
|
-
pry_tester = Pry.new(:input => InputTester.new("raise self"),
|
185
|
-
:output => @str_output,
|
186
|
-
:exception_handler => proc { was_called = true })
|
187
|
-
|
188
|
-
pry_tester.rep(o)
|
189
|
-
was_called.should == true
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'should not try to catch intended exceptions' do
|
193
|
-
lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
|
194
|
-
# SIGTERM
|
195
|
-
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "repl" do
|
200
|
-
describe "basic functionality" do
|
201
|
-
it 'should set an ivar on an object and exit the repl' do
|
202
|
-
input_strings = ["@x = 10", "exit-all"]
|
203
|
-
input = InputTester.new(*input_strings)
|
204
|
-
|
205
|
-
o = Object.new
|
206
|
-
|
207
|
-
pry_tester = Pry.start(o, :input => input, :output => StringIO.new)
|
208
|
-
|
209
|
-
o.instance_variable_get(:@x).should == 10
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe "complete_expression?" do
|
214
|
-
it "should not mutate the input!" do
|
215
|
-
clean = "puts <<-FOO\nhi\nFOO\n"
|
216
|
-
a = clean.dup
|
217
|
-
Pry::Code.complete_expression?(a)
|
218
|
-
a.should == clean
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe "history arrays" do
|
223
|
-
it 'sets _ to the last result' do
|
224
|
-
res = []
|
225
|
-
input = InputTester.new *[":foo", "self << _", "42", "self << _"]
|
226
|
-
pry = Pry.new(:input => input, :output => StringIO.new)
|
227
|
-
pry.repl(res)
|
228
|
-
|
229
|
-
res.should == [:foo, 42]
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'sets out to an array with the result' do
|
233
|
-
res = {}
|
234
|
-
input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
|
235
|
-
pry = Pry.new(:input => input, :output => StringIO.new)
|
236
|
-
pry.repl(res)
|
237
|
-
|
238
|
-
res[:res].should.be.kind_of Pry::HistoryArray
|
239
|
-
res[:res][1..2].should == [:foo, 42]
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'sets _in_ to an array with the entered lines' do
|
243
|
-
res = {}
|
244
|
-
input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
|
245
|
-
pry = Pry.new(:input => input, :output => StringIO.new)
|
246
|
-
pry.repl(res)
|
247
|
-
|
248
|
-
res[:res].should.be.kind_of Pry::HistoryArray
|
249
|
-
res[:res][1..2].should == [":foo\n", "42\n"]
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'uses 100 as the size of _in_ and _out_' do
|
253
|
-
res = []
|
254
|
-
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
255
|
-
pry = Pry.new(:input => input, :output => StringIO.new)
|
256
|
-
pry.repl(res)
|
257
|
-
|
258
|
-
res.should == [100, 100]
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'can change the size of the history arrays' do
|
262
|
-
res = []
|
263
|
-
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
264
|
-
pry = Pry.new(:input => input, :output => StringIO.new,
|
265
|
-
:memory_size => 1000)
|
266
|
-
pry.repl(res)
|
267
|
-
|
268
|
-
res.should == [1000, 1000]
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'store exceptions' do
|
272
|
-
res = []
|
273
|
-
input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
|
274
|
-
pry = Pry.new(:input => input, :output => StringIO.new,
|
275
|
-
:memory_size => 1000)
|
276
|
-
pry.repl(res)
|
277
|
-
|
278
|
-
res.first.should == "foo!\n"
|
279
|
-
res.last.should.be.kind_of NoMethodError
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
describe "last_result" do
|
284
|
-
it "should be set to the most recent value" do
|
285
|
-
pry_eval("2", "_ + 82").should == 84
|
286
|
-
end
|
287
|
-
|
288
|
-
# This test needs mock_pry because the command retvals work by
|
289
|
-
# replacing the eval_string, so _ won't be modified without Pry doing
|
290
|
-
# a REPL loop.
|
291
|
-
it "should be set to the result of a command with :keep_retval" do
|
292
|
-
Pry::Commands.block_command '++', '', :keep_retval => true do |a|
|
293
|
-
a.to_i + 1
|
294
|
-
end
|
295
|
-
|
296
|
-
mock_pry('++ 86', '++ #{_}').should =~ /88/
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should be preserved over an empty line" do
|
300
|
-
pry_eval("2 + 2", " ", "\t", " ", "_ + 92").should == 96
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should be preserved when evalling a command without :keep_retval" do
|
304
|
-
pry_eval("2 + 2", "ls -l", "_ + 96").should == 100
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe "test loading rc files" do
|
309
|
-
before do
|
310
|
-
Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
|
311
|
-
Pry::LOCAL_RC_FILE.replace "spec/fixtures/testrc/../testrc"
|
312
|
-
Pry.instance_variable_set(:@initial_session, true)
|
313
|
-
end
|
314
|
-
|
315
|
-
after do
|
316
|
-
Pry::HOME_RC_FILE.replace "~/.pryrc"
|
317
|
-
Pry::LOCAL_RC_FILE.replace "./.pryrc"
|
318
|
-
Pry.config.should_load_rc = false
|
319
|
-
Object.remove_const(:TEST_RC) if defined?(TEST_RC)
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should never run the rc file twice" do
|
323
|
-
Pry.config.should_load_rc = true
|
324
|
-
|
325
|
-
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
|
326
|
-
TEST_RC.should == [0]
|
327
|
-
|
328
|
-
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
|
329
|
-
TEST_RC.should == [0]
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should not load the pryrc if it cannot expand ENV[HOME]" do
|
333
|
-
old_home = ENV['HOME']
|
334
|
-
old_rc = Pry.config.should_load_rc
|
335
|
-
ENV['HOME'] = nil
|
336
|
-
Pry.config.should_load_rc = true
|
337
|
-
lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.should.not.raise
|
338
|
-
|
339
|
-
ENV['HOME'] = old_home
|
340
|
-
Pry.config.should_load_rc = old_rc
|
341
|
-
end
|
342
|
-
|
343
|
-
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
|
344
|
-
Pry.config.should_load_rc = false
|
345
|
-
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
|
346
|
-
Object.const_defined?(:TEST_RC).should == false
|
347
|
-
end
|
348
|
-
|
349
|
-
it "should not load the rc file if #repl method invoked" do
|
350
|
-
Pry.config.should_load_rc = true
|
351
|
-
Pry.new(:input => StringIO.new("exit-all\n"), :output => StringIO.new).repl(self)
|
352
|
-
Object.const_defined?(:TEST_RC).should == false
|
353
|
-
Pry.config.should_load_rc = false
|
354
|
-
end
|
355
|
-
|
356
|
-
describe "that raise exceptions" do
|
357
|
-
before do
|
358
|
-
Pry::HOME_RC_FILE = "spec/fixtures/testrcbad"
|
359
|
-
Pry.config.should_load_rc = true
|
360
|
-
Pry.config.should_load_local_rc = false
|
361
|
-
|
362
|
-
putsed = nil
|
363
|
-
|
364
|
-
# YUCK! horrible hack to get round the fact that output is not configured
|
365
|
-
# at the point this message is printed.
|
366
|
-
(class << Pry; self; end).send(:define_method, :puts) { |str|
|
367
|
-
putsed = str
|
368
|
-
}
|
369
|
-
|
370
|
-
@doing_it = lambda{
|
371
|
-
Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => StringIO.new)
|
372
|
-
putsed
|
373
|
-
}
|
374
|
-
end
|
375
|
-
|
376
|
-
after do
|
377
|
-
Object.remove_const(:TEST_BEFORE_RAISE)
|
378
|
-
Object.remove_const(:TEST_AFTER_RAISE)
|
379
|
-
(class << Pry; undef_method :puts; end)
|
380
|
-
end
|
381
|
-
|
382
|
-
it "should not raise exceptions" do
|
383
|
-
@doing_it.should.not.raise
|
384
|
-
end
|
385
|
-
|
386
|
-
it "should continue to run pry" do
|
387
|
-
@doing_it[]
|
388
|
-
Object.const_defined?(:TEST_BEFORE_RAISE).should == true
|
389
|
-
Object.const_defined?(:TEST_AFTER_RAISE).should == true
|
390
|
-
end
|
391
|
-
|
392
|
-
it "should output an error" do
|
393
|
-
@doing_it.call.split("\n").first.should ==
|
394
|
-
"Error loading spec/fixtures/testrcbad: messin with ya"
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
describe "nesting" do
|
400
|
-
after do
|
401
|
-
Pry.reset_defaults
|
402
|
-
Pry.color = false
|
403
|
-
end
|
404
|
-
|
405
|
-
it 'should nest properly' do
|
406
|
-
Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
|
407
|
-
|
408
|
-
Pry.output = @str_output
|
409
|
-
|
410
|
-
o = Object.new
|
411
|
-
|
412
|
-
pry_tester = o.pry
|
413
|
-
@str_output.string.should =~ /nest:3/
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
describe "defining methods" do
|
418
|
-
it 'should define a method on the singleton class of an object when performing "def meth;end" inside the object' do
|
419
|
-
[Object.new, {}, []].each do |val|
|
420
|
-
str_input = StringIO.new("def hello;end")
|
421
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
422
|
-
|
423
|
-
val.methods(false).map(&:to_sym).include?(:hello).should == true
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
it 'should define an instance method on the module when performing "def meth;end" inside the module' do
|
428
|
-
str_input = StringIO.new("def hello;end")
|
429
|
-
hello = Module.new
|
430
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
431
|
-
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'should define an instance method on the class when performing "def meth;end" inside the class' do
|
435
|
-
str_input = StringIO.new("def hello;end")
|
436
|
-
hello = Class.new
|
437
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
438
|
-
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
439
|
-
end
|
440
|
-
|
441
|
-
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
|
442
|
-
# should include float in here, but test fails for some reason
|
443
|
-
# on 1.8.7, no idea why!
|
444
|
-
[:test, 0, true, false, nil].each do |val|
|
445
|
-
str_input = StringIO.new("def hello;end")
|
446
|
-
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
447
|
-
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
448
|
-
end
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
describe "Object#pry" do
|
453
|
-
|
454
|
-
after do
|
455
|
-
Pry.reset_defaults
|
456
|
-
Pry.color = false
|
457
|
-
end
|
458
|
-
|
459
|
-
it "should start a pry session on the receiver (first form)" do
|
460
|
-
Pry.input = InputTester.new("self", "exit-all")
|
461
|
-
|
462
|
-
str_output = StringIO.new
|
463
|
-
Pry.output = str_output
|
464
|
-
|
465
|
-
20.pry
|
466
|
-
|
467
|
-
str_output.string.should =~ /20/
|
468
|
-
end
|
469
|
-
|
470
|
-
it "should start a pry session on the receiver (second form)" do
|
471
|
-
Pry.input = InputTester.new("self", "exit-all")
|
472
|
-
|
473
|
-
str_output = StringIO.new
|
474
|
-
Pry.output = str_output
|
475
|
-
|
476
|
-
pry 20
|
477
|
-
|
478
|
-
str_output.string.should =~ /20/
|
479
|
-
end
|
480
|
-
|
481
|
-
it "should raise if more than two arguments are passed to Object#pry" do
|
482
|
-
lambda { pry(20, :quiet, :input => Readline) }.should.raise ArgumentError
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
describe "Pry.binding_for" do
|
487
|
-
it 'should return TOPLEVEL_BINDING if parameter self is main' do
|
488
|
-
_main_ = lambda { TOPLEVEL_BINDING.eval('self') }
|
489
|
-
Pry.binding_for(_main_.call).is_a?(Binding).should == true
|
490
|
-
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
491
|
-
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
492
|
-
end
|
493
|
-
end
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
|
-
describe 'setting custom options' do
|
498
|
-
it 'should not raise for unrecognized options' do
|
499
|
-
should.not.raise?(NoMethodError) {
|
500
|
-
instance = Pry.new(:custom_option => 'custom value')
|
501
|
-
}
|
502
|
-
end
|
503
|
-
end
|
504
|
-
end
|
data/spec/run_command_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry.run_command" do
|
4
|
-
before do
|
5
|
-
o = Object.new
|
6
|
-
def o.drum
|
7
|
-
"roken is dodelijk"
|
8
|
-
end
|
9
|
-
@context = Pry.binding_for(o)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'performs a simple ls' do
|
13
|
-
@context.eval("hokey_pokey = 10")
|
14
|
-
Pry.run_command "ls", :context => @context, :output => out = StringIO.new
|
15
|
-
out.string.should =~ /hokey_pokey/
|
16
|
-
end
|
17
|
-
|
18
|
-
if !PryTestHelpers.mri18_and_no_real_source_location?
|
19
|
-
# This is a regression test as 0.9.11 broke this behaviour
|
20
|
-
it 'can perform a show-source' do
|
21
|
-
Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new
|
22
|
-
out.string.should =~ /roken is dodelijk/
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/sticky_locals_spec.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Sticky locals (_file_ and friends)" do
|
4
|
-
it 'locals should all exist upon initialization' do
|
5
|
-
proc {
|
6
|
-
pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_'
|
7
|
-
}.should.not.raise(NameError)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'locals should still exist after cd-ing into a new context' do
|
11
|
-
proc {
|
12
|
-
pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_'
|
13
|
-
}.should.not.raise(NameError)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'locals should keep value after cd-ing (_pry_)' do
|
17
|
-
pry_tester.tap do |t|
|
18
|
-
pry = t.eval '_pry_'
|
19
|
-
t.eval 'cd 0'
|
20
|
-
t.eval('_pry_').should == pry
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Using mock_pry here until we figure out exception handling
|
25
|
-
it 'locals should keep value after cd-ing (_ex_)' do
|
26
|
-
mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'locals should keep value after cd-ing (_file_ and _dir_)' do
|
30
|
-
Pry.commands.command "file-and-dir-test" do
|
31
|
-
set_file_and_dir_locals("/blah/ostrich.rb")
|
32
|
-
end
|
33
|
-
|
34
|
-
pry_eval('file-and-dir-test', 'cd 0', '_file_').
|
35
|
-
should =~ /\/blah\/ostrich\.rb/
|
36
|
-
|
37
|
-
pry_eval('file-and-dir-test', 'cd 0', '_dir_').
|
38
|
-
should =~ /\/blah/
|
39
|
-
|
40
|
-
Pry.commands.delete "file-and-dir-test"
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "User defined sticky locals" do
|
44
|
-
describe "setting as Pry.config option" do
|
45
|
-
it 'should define a new sticky local for the session (normal value)' do
|
46
|
-
Pry.config.extra_sticky_locals[:test_local] = :john
|
47
|
-
|
48
|
-
o = Object.new
|
49
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
50
|
-
"exit-all")) do
|
51
|
-
Pry.start(o)
|
52
|
-
end
|
53
|
-
|
54
|
-
o.instance_variable_get(:@value).should == :john
|
55
|
-
Pry.config.extra_sticky_locals = {}
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should define a new sticky local for the session (proc)' do
|
59
|
-
Pry.config.extra_sticky_locals[:test_local] = proc { :john }
|
60
|
-
|
61
|
-
o = Object.new
|
62
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
63
|
-
"exit-all")) do
|
64
|
-
Pry.start(o)
|
65
|
-
end
|
66
|
-
|
67
|
-
o.instance_variable_get(:@value).should == :john
|
68
|
-
Pry.config.extra_sticky_locals = {}
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "passing in as hash option when creating pry instance" do
|
74
|
-
it 'should define a new sticky local for the session (normal value)' do
|
75
|
-
o = Object.new
|
76
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
77
|
-
"exit-all")) do
|
78
|
-
Pry.start(o, :extra_sticky_locals => { :test_local => :john } )
|
79
|
-
end
|
80
|
-
|
81
|
-
o.instance_variable_get(:@value).should == :john
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should define multiple sticky locals' do
|
85
|
-
o = Object.new
|
86
|
-
redirect_pry_io(InputTester.new("@value1 = test_local1",
|
87
|
-
"@value2 = test_local2",
|
88
|
-
"exit-all")) do
|
89
|
-
Pry.start(o, :extra_sticky_locals => { :test_local1 => :john ,
|
90
|
-
:test_local2 => :carl} )
|
91
|
-
end
|
92
|
-
|
93
|
-
o.instance_variable_get(:@value1).should == :john
|
94
|
-
o.instance_variable_get(:@value2).should == :carl
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
it 'should define a new sticky local for the session (as Proc)' do
|
99
|
-
o = Object.new
|
100
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
101
|
-
"exit-all")) do
|
102
|
-
Pry.start(o, :extra_sticky_locals => { :test_local => proc { :john }} )
|
103
|
-
end
|
104
|
-
|
105
|
-
o.instance_variable_get(:@value).should == :john
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "hash option value should override config value" do
|
110
|
-
it 'should define a new sticky local for the session (normal value)' do
|
111
|
-
Pry.config.extra_sticky_locals[:test_local] = :john
|
112
|
-
|
113
|
-
o = Object.new
|
114
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
115
|
-
"exit-all")) do
|
116
|
-
Pry.start(o, :extra_sticky_locals => { :test_local => :carl })
|
117
|
-
end
|
118
|
-
|
119
|
-
o.instance_variable_get(:@value).should == :carl
|
120
|
-
Pry.config.extra_sticky_locals = {}
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should create a new sticky local' do
|
125
|
-
o = Object.new
|
126
|
-
pi = Pry.new
|
127
|
-
pi.add_sticky_local(:test_local) { :test_value }
|
128
|
-
pi.input, pi.output = InputTester.new("@value = test_local", "exit-all"), StringIO.new
|
129
|
-
pi.repl(o)
|
130
|
-
|
131
|
-
o.instance_variable_get(:@value).should == :test_value
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should still exist after cd-ing into new binding' do
|
135
|
-
o = Object.new
|
136
|
-
o2 = Object.new
|
137
|
-
o.instance_variable_set(:@o2, o2)
|
138
|
-
pi = Pry.new
|
139
|
-
pi.add_sticky_local(:test_local) { :test_value }
|
140
|
-
pi.input = InputTester.new("cd @o2\n",
|
141
|
-
"@value = test_local", "exit-all")
|
142
|
-
pi.output = StringIO.new
|
143
|
-
pi.repl(o)
|
144
|
-
|
145
|
-
o2.instance_variable_get(:@value).should == :test_value
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should provide different values for successive block invocations' do
|
149
|
-
pry = Pry.new
|
150
|
-
pry.add_sticky_local(:test_local) { rand }
|
151
|
-
value1 = pry.evaluate_ruby 'test_local'
|
152
|
-
value2 = pry.evaluate_ruby 'test_local'
|
153
|
-
value1.should.not == value2
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|