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.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +126 -182
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -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