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,62 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::InputCompleter do
4
-
5
- before do
6
- # The AMQP gem has some classes like this:
7
- # pry(main)> AMQP::Protocol::Test::ContentOk.name
8
- # => :content_ok
9
- module SymbolyName
10
- def self.name; :symboly_name; end
11
- end
12
- end
13
-
14
- after do
15
- Object.remove_const :SymbolyName
16
- end
17
-
18
- # another jruby hack :((
19
- if !Pry::Helpers::BaseHelpers.jruby?
20
- it "should not crash if there's a Module that has a symbolic name." do
21
- completer = Pry::InputCompleter.build_completion_proc(Pry.binding_for(Object.new))
22
- lambda{ completer.call "a.to_s." }.should.not.raise Exception
23
- end
24
- end
25
-
26
- it 'should take parenthesis and other characters into account for symbols' do
27
- b = Pry.binding_for(Object.new)
28
- completer = Pry::InputCompleter.build_completion_proc(b)
29
-
30
- lambda { completer.call(":class)") }.should.not.raise(RegexpError)
31
- end
32
-
33
- it 'should complete instance variables' do
34
- object = Object.new
35
-
36
- object.instance_variable_set(:'@name', 'Pry')
37
- object.class.send(:class_variable_set, :'@@number', 10)
38
-
39
- object.instance_variables.map { |v| v.to_sym } \
40
- .include?(:'@name').should == true
41
-
42
- object.class.class_variables.map { |v| v.to_sym } \
43
- .include?(:'@@number').should == true
44
-
45
- completer = Pry::InputCompleter.build_completion_proc(
46
- Pry.binding_for(object)
47
- )
48
-
49
- # Complete instance variables.
50
- completer.call('@na').include?('@name').should == true
51
- completer.call('@name.down').include?('@name.downcase').should == true
52
-
53
- # Complete class variables.
54
- completer = Pry::InputCompleter.build_completion_proc(
55
- Pry.binding_for(object.class)
56
- )
57
-
58
- completer.call('@@nu').include?('@@number').should == true
59
- completer.call('@@number.cl').include?('@@number.class').should == true
60
- end
61
- end
62
-
@@ -1,45 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::DEFAULT_CONTROL_D_HANDLER do
4
- describe 'control-d press' do
5
- before do
6
- @control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
7
- @binding_stack = "self.binding_stack = _pry_.binding_stack.dup"
8
- end
9
-
10
- describe 'in an expression' do
11
- it 'should clear out passed string' do
12
- str = "hello world"
13
- Pry::DEFAULT_CONTROL_D_HANDLER.call(str, nil)
14
- str.should == ""
15
- end
16
- end
17
-
18
- describe 'at top-level session' do
19
- it 'should break out of a REPL loop' do
20
- instance = nil
21
- redirect_pry_io(InputTester.new(@control_d)) do
22
- instance = Pry.new
23
- instance.repl
24
- end
25
-
26
- instance.binding_stack.should.be.empty
27
- end
28
- end
29
-
30
- describe 'in a nested session' do
31
- it 'should pop last binding from the binding stack' do
32
- base = OpenStruct.new
33
- base.obj = OpenStruct.new
34
-
35
- redirect_pry_io(InputTester.new("cd obj", "self.stack_size = _pry_.binding_stack.size",
36
- @control_d, "self.stack_size = _pry_.binding_stack.size", "exit-all")) do
37
- Pry.start(base)
38
- end
39
-
40
- base.obj.stack_size.should == 2
41
- base.stack_size.should == 1
42
- end
43
- end
44
- end
45
- end
@@ -1,5 +0,0 @@
1
- <html>
2
-
3
- Look at me, testing my erb!
4
-
5
- </html>
@@ -1,318 +0,0 @@
1
- require 'helper'
2
-
3
- describe 'Pry::DefaultCommands::Cd' do
4
- before do
5
- @o, @obj = Object.new, Object.new
6
- @obj.instance_variable_set(:@x, 66)
7
- @obj.instance_variable_set(:@y, 79)
8
- @o.instance_variable_set(:@obj, @obj)
9
-
10
- # Shortcuts. They save a lot of typing.
11
- @os1 = "Pad.os1 = _pry_.command_state['cd'].old_stack.dup"
12
- @os2 = "Pad.os2 = _pry_.command_state['cd'].old_stack.dup"
13
-
14
- @bs1 = "Pad.bs1 = _pry_.binding_stack.dup"
15
- @bs2 = "Pad.bs2 = _pry_.binding_stack.dup"
16
- @bs3 = "Pad.bs3 = _pry_.binding_stack.dup"
17
-
18
- @self = "Pad.self = self"
19
- @inner = "Pad.inner = self"
20
- @outer = "Pad.outer = self"
21
- end
22
-
23
- after do
24
- Pad.clear
25
- end
26
-
27
- describe 'state' do
28
- it 'should not to be set up in fresh instance' do
29
- redirect_pry_io(InputTester.new(@os1, "exit-all")) do
30
- Pry.start(@o)
31
- end
32
-
33
- Pad.os1.should == nil
34
- end
35
- end
36
-
37
- describe 'old stack toggling with `cd -`' do
38
- describe 'in fresh pry instance' do
39
- it 'should not toggle when there is no old stack' do
40
- redirect_pry_io(InputTester.new("cd -", @bs1, "cd -", @bs2, "exit-all")) do
41
- Pry.start(@o)
42
- end
43
-
44
- Pad.bs1.map { |v| v.eval("self") }.should == [@o]
45
- Pad.bs2.map { |v| v.eval("self") }.should == [@o]
46
- end
47
- end
48
-
49
- describe 'when an error was raised' do
50
- it 'should ensure cd @ raises SyntaxError' do
51
- mock_pry("cd @").should =~ /SyntaxError/
52
- end
53
-
54
- it 'should not toggle and should keep correct old stack' do
55
- redirect_pry_io(InputTester.new("cd @", @os1, "cd -", @os2, "exit-all")) do
56
- Pry.start(@o)
57
- end
58
-
59
- Pad.os1.should == []
60
- Pad.os2.should == []
61
- end
62
-
63
- it 'should not toggle and should keep correct current binding stack' do
64
- redirect_pry_io(InputTester.new("cd @", @bs1, "cd -", @bs2, "exit-all")) do
65
- Pry.start(@o)
66
- end
67
-
68
- Pad.bs1.map { |v| v.eval("self") }.should == [@o]
69
- Pad.bs2.map { |v| v.eval("self") }.should == [@o]
70
- end
71
- end
72
-
73
- describe 'when using simple cd syntax' do
74
- it 'should toggle' do
75
- redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", @bs1,
76
- "cd -", @bs2, "exit-all")) do
77
- Pry.start(@o)
78
- end
79
-
80
- Pad.bs1.map { |v| v.eval("self") }.should == [@o]
81
- Pad.bs2.map { |v| v.eval("self") }.should == [@o, :mon_dogg]
82
- end
83
- end
84
-
85
- describe "when using complex cd syntax" do
86
- it 'should toggle with a complex path (simple case)' do
87
- redirect_pry_io(InputTester.new("cd 1/2/3", "cd -", @bs1,
88
- "cd -", @bs2, "exit-all")) do
89
- Pry.start(@o)
90
- end
91
-
92
- Pad.bs1.map { |v| v.eval('self') }.should == [@o]
93
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, 1, 2, 3]
94
- end
95
-
96
- it 'should toggle with a complex path (more complex case)' do
97
- redirect_pry_io(InputTester.new("cd 1/2/3", "cd ../4", "cd -",
98
- @bs1, "cd -", @bs2, "exit-all")) do
99
- Pry.start(@o)
100
- end
101
-
102
- Pad.bs1.map { |v| v.eval('self') }.should == [@o, 1, 2, 3]
103
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, 1, 2, 4]
104
- end
105
- end
106
-
107
- describe 'series of cd calls' do
108
- it 'should toggle with fuzzy `cd -` calls' do
109
- redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", "cd 42", "cd -",
110
- @bs1, "cd -", @bs2, "exit-all")) do
111
- Pry.start(@o)
112
- end
113
-
114
- Pad.bs1.map { |v| v.eval('self') }.should == [@o]
115
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, 42]
116
- end
117
- end
118
-
119
- describe 'when using cd ..' do
120
- it 'should toggle with a simple path' do
121
- redirect_pry_io(InputTester.new("cd :john_dogg", "cd ..", @bs1,
122
- "cd -", @bs2, "exit-all")) do
123
- Pry.start(@o)
124
- end
125
-
126
- Pad.bs1.map { |v| v.eval('self') }.should == [@o]
127
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, :john_dogg]
128
- end
129
-
130
- it 'should toggle with a complex path' do
131
- redirect_pry_io(InputTester.new("cd 1/2/3/../4", "cd -", @bs1,
132
- "cd -", @bs2, "exit-all")) do
133
- Pry.start(@o)
134
- end
135
-
136
- Pad.bs1.map { |v| v.eval('self') }.should == [@o]
137
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, 1, 2, 4]
138
- end
139
- end
140
-
141
- describe 'when using cd ::' do
142
- it 'should toggle' do
143
- redirect_pry_io(InputTester.new("cd ::", "cd -", @bs1,
144
- "cd -", @bs2, "exit-all")) do
145
- Pry.start(@o)
146
- end
147
-
148
- Pad.bs1.map { |v| v.eval('self') }.should == [@o]
149
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, TOPLEVEL_BINDING.eval("self")]
150
- end
151
- end
152
-
153
- describe 'when using cd /' do
154
- it 'should toggle' do
155
- redirect_pry_io(InputTester.new("cd /", "cd -", @bs1, "cd :john_dogg",
156
- "cd /", "cd -", @bs2, "exit-all")) do
157
- Pry.start(@o)
158
- end
159
-
160
- Pad.bs1.map { |v| v.eval('self') }.should == [@o]
161
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, :john_dogg]
162
- end
163
- end
164
-
165
- describe 'when using ^D (Control-D) key press' do
166
- before do
167
- @control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
168
- end
169
-
170
- it 'should keep correct old binding' do
171
- redirect_pry_io(InputTester.new("cd :john_dogg", "cd :mon_dogg",
172
- "cd :kyr_dogg", @control_d, @bs1, "cd -",
173
- @bs2, "cd -", @bs3, "exit-all")) do
174
- Pry.start(@o)
175
- end
176
-
177
- Pad.bs1.map { |v| v.eval('self') }.should == [@o, :john_dogg, :mon_dogg]
178
- Pad.bs2.map { |v| v.eval('self') }.should == [@o, :john_dogg, :mon_dogg, :kyr_dogg]
179
- Pad.bs3.map { |v| v.eval('self') }.should == [@o, :john_dogg, :mon_dogg]
180
- end
181
- end
182
- end
183
-
184
- it 'should cd into simple input' do
185
- redirect_pry_io(InputTester.new("cd :mon_ouie", @inner, "exit-all")) do
186
- Pry.start(@o)
187
- end
188
-
189
- Pad.inner.should == :mon_ouie
190
- end
191
-
192
- it 'should break out of session with cd ..' do
193
- redirect_pry_io(InputTester.new("cd :inner", @inner, "cd ..", @outer, "exit-all")) do
194
- Pry.start(:outer)
195
- end
196
-
197
- Pad.inner.should == :inner
198
- Pad.outer.should == :outer
199
- end
200
-
201
- it "should not leave the REPL session when given 'cd ..'" do
202
- redirect_pry_io(InputTester.new("cd ..", @self, "exit-all")) do
203
- Pry.start(@o)
204
- end
205
-
206
- Pad.self.should == @o
207
- end
208
-
209
- it 'should break out to outer-most session with cd /' do
210
- redirect_pry_io(InputTester.new("cd :inner", @inner, "cd 5", "Pad.five = self",
211
- "cd /", @outer, "exit-all")) do
212
- Pry.start(:outer)
213
- end
214
-
215
- Pad.inner.should == :inner
216
- Pad.five.should == 5
217
- Pad.outer.should == :outer
218
- end
219
-
220
- it 'should break out to outer-most session with just cd (no args)' do
221
- redirect_pry_io(InputTester.new("cd :inner", @inner, "cd 5", "Pad.five = self",
222
- "cd", @outer, "exit-all")) do
223
- Pry.start(:outer)
224
- end
225
-
226
- Pad.inner.should == :inner
227
- Pad.five.should == 5
228
- Pad.outer.should == :outer
229
- end
230
-
231
- it 'should cd into an object and its ivar using cd obj/@ivar syntax' do
232
- redirect_pry_io(InputTester.new("cd @obj/@x", @bs1, "exit-all")) do
233
- Pry.start(@o)
234
- end
235
-
236
- Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 66]
237
- end
238
-
239
- it 'should cd into an object and its ivar using cd obj/@ivar/ syntax (note following /)' do
240
- redirect_pry_io(InputTester.new("cd @obj/@x/", @bs1, "exit-all")) do
241
- Pry.start(@o)
242
- end
243
-
244
- Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 66]
245
- end
246
-
247
- it 'should cd into previous object and its local using cd ../local syntax' do
248
- redirect_pry_io(InputTester.new("cd @obj", "local = :local", "cd @x",
249
- "cd ../local", @bs1, "exit-all")) do
250
- Pry.start(@o)
251
- end
252
-
253
- Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, :local]
254
- end
255
-
256
- it 'should cd into an object and its ivar and back again using cd obj/@ivar/.. syntax' do
257
- redirect_pry_io(InputTester.new("cd @obj/@x/..", @bs1, "exit-all")) do
258
- Pry.start(@o)
259
- end
260
-
261
- Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj]
262
- end
263
-
264
- it 'should cd into an object and its ivar and back and then into another ivar using cd obj/@ivar/../@y syntax' do
265
- redirect_pry_io(InputTester.new("cd @obj/@x/../@y", @bs1, "exit-all")) do
266
- Pry.start(@o)
267
- end
268
-
269
- Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 79]
270
- end
271
-
272
- it 'should cd back to top-level and then into another ivar using cd /@ivar/ syntax' do
273
- redirect_pry_io(InputTester.new("@z = 20", "cd @obj/@x/", "cd /@z", @bs1, "exit-all")) do
274
- Pry.start(@o)
275
- end
276
-
277
- Pad.bs1.map { |v| v.eval("self") }.should == [@o, 20]
278
- end
279
-
280
- it 'should start a session on TOPLEVEL_BINDING with cd ::' do
281
- redirect_pry_io(InputTester.new("cd ::", @self, "exit-all")) do
282
- Pry.start(@o)
283
- end
284
-
285
- Pad.self.should == TOPLEVEL_BINDING.eval("self")
286
- end
287
-
288
- it 'should cd into complex input (with spaces)' do
289
- def @o.hello(x, y, z)
290
- :mon_ouie
291
- end
292
-
293
- redirect_pry_io(InputTester.new("cd hello 1, 2, 3", @self, "exit-all")) do
294
- Pry.start(@o)
295
- end
296
-
297
- Pad.self.should == :mon_ouie
298
- end
299
-
300
- it 'should not cd into complex input when it encounters an exception' do
301
- redirect_pry_io(InputTester.new("cd 1/2/swoop_a_doop/3", @bs1, "exit-all")) do
302
- Pry.start(@o)
303
- end
304
-
305
- Pad.bs1.map { |v| v.eval("self") }.should == [@o]
306
- end
307
-
308
- # Regression test for ticket #516.
309
- #it 'should be able to cd into the Object BasicObject.' do
310
- # mock_pry('cd BasicObject.new').should.not =~ /\Aundefined method `__binding__'/
311
- #end
312
-
313
- # Regression test for ticket #516
314
- # Possibly move higher up.
315
- it 'should not fail with undefined BasicObject#is_a?' do
316
- mock_pry('cd BasicObject.new').should.not =~ /undefined method `is_a\?'/
317
- end
318
- end
@@ -1,280 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Pry::DefaultCommands::Context" do
4
- describe "exit-all" do
5
- it 'should break out of the repl loop of Pry instance and return nil' do
6
- redirect_pry_io(InputTester.new("exit-all")) do
7
- Pry.new.repl(0).should == nil
8
- end
9
- end
10
-
11
- it 'should break out of the repl loop of Pry instance wth a user specified value' do
12
- redirect_pry_io(InputTester.new("exit-all 'message'")) do
13
- Pry.new.repl(0).should == 'message'
14
- end
15
- end
16
-
17
- it 'should break of the repl loop even if multiple bindings still on stack' do
18
- ins = nil
19
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "exit-all 'message'")) do
20
- ins = Pry.new.tap { |v| v.repl(0).should == 'message' }
21
- end
22
- end
23
-
24
- it 'binding_stack should be empty after breaking out of the repl loop' do
25
- ins = nil
26
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "exit-all")) do
27
- ins = Pry.new.tap { |v| v.repl(0) }
28
- end
29
-
30
- ins.binding_stack.empty?.should == true
31
- end
32
- end
33
-
34
- describe "whereami" do
35
- it 'should work with methods that have been undefined' do
36
- class Cor
37
- def blimey!
38
- Cor.send :undef_method, :blimey!
39
- # using [.] so the regex doesn't match itself
40
- mock_pry(binding, 'whereami').should =~ /self[.]blimey!/
41
- end
42
- end
43
-
44
- Cor.new.blimey!
45
- Object.remove_const(:Cor)
46
- end
47
-
48
- it 'should work in objects with no method methods' do
49
- class Cor
50
- def blimey!
51
- mock_pry(binding, 'whereami').should =~ /Cor[#]blimey!/
52
- end
53
-
54
- def method; "moo"; end
55
- end
56
- Cor.new.blimey!
57
- Object.remove_const(:Cor)
58
- end
59
-
60
- it 'should properly set _file_, _line_ and _dir_' do
61
- class Cor
62
- def blimey!
63
- mock_pry(binding, 'whereami', '_file_') \
64
- .should =~ /#{File.expand_path(__FILE__)}/
65
- end
66
- end
67
-
68
- Cor.new.blimey!
69
- Object.remove_const(:Cor)
70
- end
71
-
72
- it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do
73
- class Cor
74
- def blimey!
75
- eval <<-END, binding, "test/test_default_commands/example.erb", 1
76
- mock_pry(binding, 'whereami')
77
- END
78
- end
79
- end
80
-
81
- Cor.instance_method(:blimey!).source.should =~ /mock_pry/
82
-
83
- Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
84
- Object.remove_const(:Cor)
85
- end
86
-
87
- it 'should show description and correct code when @method.source_location would raise an error' do
88
- class Cor
89
- eval <<-END, binding, "test/test_default_commands/example.erb", 1
90
- def blimey!
91
- mock_pry(binding, 'whereami')
92
- end
93
- END
94
- end
95
-
96
- lambda{
97
- Cor.instance_method(:blimey!).source
98
- }.should.raise(MethodSource::SourceNotFoundError)
99
-
100
- Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
101
- Object.remove_const(:Cor)
102
-
103
- end
104
-
105
- it 'should display a description and and error if reading the file goes wrong' do
106
- class Cor
107
- def blimey!
108
- eval <<-END, binding, "not.found.file.erb", 7
109
- mock_pry(binding, 'whereami')
110
- END
111
- end
112
- end
113
-
114
- Cor.new.blimey!.should =~ /From: not.found.file.erb @ line 7 Cor#blimey!:\n\nError: Cannot open "not.found.file.erb" for reading./m
115
- Object.remove_const(:Cor)
116
- end
117
-
118
- it 'should show code window (not just method source) if parameter passed to whereami' do
119
- class Cor
120
- def blimey!
121
- mock_pry(binding, 'whereami 3').should =~ /class Cor/
122
- end
123
- end
124
- Cor.new.blimey!
125
- Object.remove_const(:Cor)
126
- end
127
-
128
- it 'should use Pry.config.default_window_size for window size when outside a method context' do
129
- old_size, Pry.config.default_window_size = Pry.config.default_window_size, 1
130
- :litella
131
- :pig
132
- out = mock_pry(binding, 'whereami')
133
- :punk
134
- :sanders
135
-
136
- out.should.not =~ /:litella/
137
- out.should =~ /:pig/
138
- out.should =~ /:punk/
139
- out.should.not =~ /:sanders/
140
-
141
- Pry.config.default_window_size = old_size
142
- end
143
-
144
- it "should work at the top level" do
145
- mock_pry(Pry.toplevel_binding, 'whereami').should =~ /At the top level/
146
- end
147
-
148
- it "should work inside a class" do
149
- mock_pry(Pry.binding_for(Pry), 'whereami').should =~ /Inside Pry/
150
- end
151
-
152
- it "should work inside an object" do
153
- mock_pry(Pry.binding_for(Object.new), 'whereami').should =~ /Inside #<Object/
154
- end
155
- end
156
-
157
- describe "exit" do
158
- it 'should pop a binding with exit' do
159
- b = Pry.binding_for(:outer)
160
- b.eval("x = :inner")
161
-
162
- redirect_pry_io(InputTester.new("cd x", "$inner = self;", "exit", "$outer = self", "exit-all")) do
163
- b.pry
164
- end
165
- $inner.should == :inner
166
- $outer.should == :outer
167
- end
168
-
169
- it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit' do
170
- Pry.start(0, :input => StringIO.new("exit")).should == nil
171
- end
172
-
173
- it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit, and return user-given value' do
174
- Pry.start(0, :input => StringIO.new("exit :john")).should == :john
175
- end
176
-
177
- it 'should break out the repl loop of Pry instance even after an exception in user-given value' do
178
- redirect_pry_io(InputTester.new("exit = 42", "exit")) do
179
- ins = Pry.new.tap { |v| v.repl(0).should == nil }
180
- end
181
- end
182
- end
183
-
184
- describe "jump-to" do
185
- before do
186
- @str_output = StringIO.new
187
- end
188
-
189
- it 'should jump to the proper binding index in the stack' do
190
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 1", "$blah = self", "exit-all")) do
191
- Pry.start(0)
192
- end
193
-
194
- $blah.should == 1
195
- end
196
-
197
- it 'should print error when trying to jump to a non-existent binding index' do
198
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 100", "exit-all"), @str_output) do
199
- Pry.start(0)
200
- end
201
-
202
- @str_output.string.should =~ /Invalid nest level/
203
- end
204
-
205
- it 'should print error when trying to jump to the same binding index' do
206
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 2", "exit-all"), @str_output) do
207
- Pry.new.repl(0)
208
- end
209
-
210
- @str_output.string.should =~ /Already/
211
- end
212
- end
213
-
214
- describe "exit-program" do
215
- it 'should raise SystemExit' do
216
- redirect_pry_io(InputTester.new("exit-program")) do
217
- lambda { Pry.new.repl(0).should == 0 }.should.raise SystemExit
218
- end
219
- end
220
-
221
- it 'should exit the program with the provided value' do
222
- redirect_pry_io(InputTester.new("exit-program 66")) do
223
- begin
224
- Pry.new.repl(0)
225
- rescue SystemExit => e
226
- e.status.should == 66
227
- end
228
- end
229
- end
230
- end
231
-
232
- describe "raise-up" do
233
- it "should raise the exception with raise-up" do
234
- redirect_pry_io(InputTester.new("raise NoMethodError", "raise-up NoMethodError")) do
235
- lambda { Pry.new.repl(0) }.should.raise NoMethodError
236
- end
237
- end
238
-
239
- it "should raise an unamed exception with raise-up" do
240
- redirect_pry_io(InputTester.new("raise 'stop'","raise-up 'noreally'")) do
241
- lambda { Pry.new.repl(0) }.should.raise RuntimeError, "noreally"
242
- end
243
- end
244
-
245
- it "should eat the exception at the last new pry instance on raise-up" do
246
- b = Pry.binding_for(:outer)
247
- b.eval("x = :inner")
248
-
249
- redirect_pry_io(InputTester.new("x.pry", "raise NoMethodError",
250
- "$inner = self", "raise-up NoMethodError", "$outer = self", "exit-all")) do
251
- b.pry
252
- end
253
- $inner.should == :inner
254
- $outer.should == :outer
255
- end
256
-
257
- it "should raise the most recently raised exception" do
258
- lambda { mock_pry("raise NameError, 'homographery'","raise-up") }.should.raise NameError, 'homographery'
259
- end
260
-
261
- it "should allow you to cd up and (eventually) out" do
262
- $deep = $inner = $outer = nil
263
- b = Pry.binding_for(:outer)
264
- b.eval("x = :inner")
265
- redirect_pry_io(InputTester.new("cd x", "raise NoMethodError","$inner = self",
266
- "deep = :deep", "cd deep","$deep = self","raise-up NoMethodError", "raise-up", "$outer = self", "raise-up", "exit-all")) do
267
- lambda { b.pry }.should.raise NoMethodError
268
- end
269
- $deep.should == :deep
270
- $inner.should == :inner
271
- $outer.should == :outer
272
- end
273
- end
274
-
275
- describe "raise-up!" do
276
- it "should jump immediately out of nested context's" do
277
- lambda { mock_pry("cd 1", "cd 2", "cd 3", "raise-up! 'fancy that...'") }.should.raise RuntimeError, 'fancy that...'
278
- end
279
- end
280
- end