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,41 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry do
4
- describe "output failsafe" do
5
- after do
6
- Pry.config.print = Pry::DEFAULT_PRINT
7
- end
8
-
9
- it "should catch serialization exceptions" do
10
- Pry.config.print = lambda { |*a| raise "catch-22" }
11
-
12
- lambda {
13
- mock_pry("1")
14
- }.should.not.raise
15
- end
16
-
17
- it "should display serialization exceptions" do
18
- Pry.config.print = lambda { |*a| raise "catch-22" }
19
-
20
- mock_pry("1").should =~ /\(pry\) output error: #<RuntimeError: catch-22>/
21
- end
22
-
23
- it "should catch errors serializing exceptions" do
24
- Pry.config.print = lambda do |*a|
25
- raise Exception.new("catch-22").tap{ |e| class << e; def inspect; raise e; end; end }
26
- end
27
-
28
- mock_pry("1").should =~ /\(pry\) output error: failed to show result/
29
- end
30
- end
31
-
32
- describe "DEFAULT_PRINT" do
33
- it "should output the right thing" do
34
- mock_pry("{:a => 1}").should =~ /\{:a=>1\}/
35
- end
36
-
37
- it "should not be phased by un-inspectable things" do
38
- mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<NastyClass:0x.*?>/
39
- end
40
- end
41
- end
@@ -1,155 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Sticky locals (_file_ and friends)" do
4
- it 'locals should all exist upon initialization' do
5
- mock_pry("_file_").should.not =~ /NameError/
6
- mock_pry("_dir_").should.not =~ /NameError/
7
- mock_pry("_ex_").should.not =~ /NameError/
8
- mock_pry("_pry_").should.not =~ /NameError/
9
- mock_pry("_").should.not =~ /NameError/
10
- end
11
-
12
- it 'locals should still exist after cd-ing into a new context' do
13
- mock_pry("cd 0", "_file_").should.not =~ /NameError/
14
- mock_pry("cd 0","_dir_").should.not =~ /NameError/
15
- mock_pry("cd 0","_ex_").should.not =~ /NameError/
16
- mock_pry("cd 0","_pry_").should.not =~ /NameError/
17
- mock_pry("cd 0","_").should.not =~ /NameError/
18
- end
19
-
20
- it 'locals should keep value after cd-ing(_pry_ and _ex_)' do
21
- mock_pry("$x = _pry_;", "cd 0", "_pry_ == $x").should =~ /true/
22
- mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
23
- end
24
-
25
- it 'locals should keep value after cd-ing (_file_ and _dir_)' do
26
- Pry.commands.command "file-and-dir-test" do
27
- set_file_and_dir_locals("/blah/ostrich.rb")
28
- end
29
-
30
- mock_pry("file-and-dir-test", "cd 0", "_file_").should =~ /\/blah\/ostrich\.rb/
31
- a = mock_pry("file-and-dir-test", "cd 0", "_dir_").should =~ /\/blah/
32
- Pry.commands.delete "file-and-dir-test"
33
- end
34
-
35
- describe "User defined sticky locals" do
36
- describe "setting as Pry.config option" do
37
- it 'should define a new sticky local for the session (normal value)' do
38
- Pry.config.extra_sticky_locals[:test_local] = :john
39
-
40
- o = Object.new
41
- redirect_pry_io(InputTester.new("@value = test_local",
42
- "exit-all")) do
43
- Pry.start(o)
44
- end
45
-
46
- o.instance_variable_get(:@value).should == :john
47
- Pry.config.extra_sticky_locals = {}
48
- end
49
-
50
- it 'should define a new sticky local for the session (proc)' do
51
- Pry.config.extra_sticky_locals[:test_local] = proc { :john }
52
-
53
- o = Object.new
54
- redirect_pry_io(InputTester.new("@value = test_local",
55
- "exit-all")) do
56
- Pry.start(o)
57
- end
58
-
59
- o.instance_variable_get(:@value).should == :john
60
- Pry.config.extra_sticky_locals = {}
61
- end
62
-
63
- end
64
-
65
- describe "passing in as hash option when creating pry instance" do
66
- it 'should define a new sticky local for the session (normal value)' do
67
- o = Object.new
68
- redirect_pry_io(InputTester.new("@value = test_local",
69
- "exit-all")) do
70
- Pry.start(o, :extra_sticky_locals => { :test_local => :john } )
71
- end
72
-
73
- o.instance_variable_get(:@value).should == :john
74
- end
75
-
76
- it 'should define multiple sticky locals' do
77
- o = Object.new
78
- redirect_pry_io(InputTester.new("@value1 = test_local1",
79
- "@value2 = test_local2",
80
- "exit-all")) do
81
- Pry.start(o, :extra_sticky_locals => { :test_local1 => :john ,
82
- :test_local2 => :carl} )
83
- end
84
-
85
- o.instance_variable_get(:@value1).should == :john
86
- o.instance_variable_get(:@value2).should == :carl
87
- end
88
-
89
-
90
- it 'should define a new sticky local for the session (as Proc)' do
91
- o = Object.new
92
- redirect_pry_io(InputTester.new("@value = test_local",
93
- "exit-all")) do
94
- Pry.start(o, :extra_sticky_locals => { :test_local => proc { :john }} )
95
- end
96
-
97
- o.instance_variable_get(:@value).should == :john
98
- end
99
- end
100
-
101
- describe "hash option value should override config value" do
102
- it 'should define a new sticky local for the session (normal value)' do
103
- Pry.config.extra_sticky_locals[:test_local] = :john
104
-
105
- o = Object.new
106
- redirect_pry_io(InputTester.new("@value = test_local",
107
- "exit-all")) do
108
- Pry.start(o, :extra_sticky_locals => { :test_local => :carl })
109
- end
110
-
111
- o.instance_variable_get(:@value).should == :carl
112
- Pry.config.extra_sticky_locals = {}
113
- end
114
- end
115
-
116
- it 'should create a new sticky local' do
117
- o = Object.new
118
- pi = Pry.new
119
- pi.add_sticky_local(:test_local) { :test_value }
120
- pi.input, pi.output = InputTester.new("@value = test_local", "exit-all"), StringIO.new
121
- pi.repl(o)
122
-
123
- o.instance_variable_get(:@value).should == :test_value
124
- end
125
-
126
- it 'should still exist after cd-ing into new binding' do
127
- o = Object.new
128
- o2 = Object.new
129
- o.instance_variable_set(:@o2, o2)
130
- pi = Pry.new
131
- pi.add_sticky_local(:test_local) { :test_value }
132
- pi.input = InputTester.new("cd @o2\n",
133
- "@value = test_local", "exit-all")
134
- pi.output = StringIO.new
135
- pi.repl(o)
136
-
137
- o2.instance_variable_get(:@value).should == :test_value
138
- end
139
-
140
- it 'should provide different values for successive block invocations' do
141
- o = Object.new
142
- pi = Pry.new
143
- v = [1, 2]
144
- pi.add_sticky_local(:test_local) { v.shift }
145
- pi.input = InputTester.new("@value1 = test_local",
146
- "@value2 = test_local", "exit-all")
147
- pi.output = StringIO.new
148
- pi.repl(o)
149
-
150
- o.instance_variable_get(:@value1).should == 1
151
- o.instance_variable_get(:@value2).should == 2
152
- end
153
- end
154
-
155
- end
@@ -1,65 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry do
4
- before do
5
- @str_output = StringIO.new
6
- end
7
-
8
- [
9
- ["p = '", "'"],
10
- ["def", "a", "(); end"],
11
- ["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
12
- ["[", ":lets,", "'list',", "[/nested/", "], things ]"],
13
- ["abc =~ /hello", "/"],
14
- ["issue = %W/", "343/"],
15
- ["pouts(<<HI, 'foo", "bar", "HI", "baz')"],
16
- ].each do |foo|
17
- it "should not raise an error on broken lines: #{foo.join("\\n")}" do
18
- redirect_pry_io(InputTester.new(*foo), @str_output) do
19
- Pry.start
20
- end
21
-
22
- @str_output.string.should.not =~ /SyntaxError/
23
- end
24
- end
25
-
26
- [
27
- ["end"],
28
- ["puts )("],
29
- ["1 1"],
30
- ["puts :"]
31
- ] + (Pry::Helpers::BaseHelpers.rbx? ? [] : [
32
- ["def", "method(1"], # in this case the syntax error is "expecting ')'".
33
- ["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
34
- ]).compact.each do |foo|
35
- it "should raise an error on invalid syntax like #{foo.inspect}" do
36
- redirect_pry_io(InputTester.new(*foo), @str_output) do
37
- Pry.start
38
- end
39
-
40
- @str_output.string.should =~ /SyntaxError/
41
- end
42
- end
43
-
44
- it "should not intefere with syntax errors explicitly raised" do
45
- redirect_pry_io(InputTester.new(%q{raise SyntaxError, "unexpected $end"}), @str_output) do
46
- Pry.start
47
- end
48
-
49
- @str_output.string.should =~ /SyntaxError/
50
- end
51
-
52
- it "should allow trailing , to continue the line" do
53
- pry = Pry.new
54
- Pry::Code.complete_expression?("puts 1, 2,").should == false
55
- end
56
-
57
- it "should complete an expression that contains a line ending with a ," do
58
- pry = Pry.new
59
- Pry::Code.complete_expression?("puts 1, 2,\n3").should == true
60
- end
61
-
62
- it "should not clobber _ex_ on a SyntaxError in the repl" do
63
- mock_pry("raise RuntimeError, 'foo';", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
64
- end
65
- end
@@ -1,174 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::WrappedModule do
4
-
5
- describe "#initialize" do
6
- it "should raise an exception when a non-module is passed" do
7
- lambda{ Pry::WrappedModule.new(nil) }.should.raise ArgumentError
8
- end
9
- end
10
-
11
- describe "candidates" do
12
- before do
13
- class Host
14
- source_files = [File.join(File.dirname(__FILE__), "candidate_helper1.rb"),
15
- File.join(File.dirname(__FILE__), "candidate_helper2.rb")]
16
-
17
- source_files.each do |file|
18
- binding.eval File.read(file), file, 1
19
- end
20
-
21
- # rank 2
22
- class CandidateTest
23
- def test6
24
- end
25
- end
26
-
27
- class ForeverAlone
28
- end
29
- end
30
- end
31
-
32
- describe "number_of_candidates" do
33
- it 'should return the correct number of candidates' do
34
- Pry::WrappedModule(Host::CandidateTest).number_of_candidates.should == 3
35
- end
36
-
37
- it 'should return 0 candidates for a class with no methods and no other definitions' do
38
- Pry::WrappedModule(Host::ForeverAlone).number_of_candidates.should == 0
39
- end
40
- end
41
-
42
- describe "ordering of candidates" do
43
- it 'should return class with largest number of methods as primary candidate' do
44
- Pry::WrappedModule(Host::CandidateTest).candidate(0).file.should =~ /helper1/
45
- end
46
-
47
- it 'should return class with second largest number of methods as second ranked candidate' do
48
- Pry::WrappedModule(Host::CandidateTest).candidate(1).file.should =~ /helper2/
49
- end
50
-
51
- it 'should return class with third largest number of methods as third ranked candidate' do
52
- Pry::WrappedModule(Host::CandidateTest).candidate(2).file.should =~ /#{__FILE__}/
53
- end
54
-
55
- it 'should raise when trying to access non-existent candidate' do
56
- lambda { Pry::WrappedModule(Host::CandidateTest).candidate(3) }.should.raise Pry::CommandError
57
- end
58
- end
59
-
60
- describe "source_location" do
61
- it 'should return primary candidates source_location by default' do
62
- wm = Pry::WrappedModule(Host::CandidateTest)
63
- wm.source_location.should == wm.candidate(0).source_location
64
- end
65
-
66
- it 'should return nil if no source_location can be found' do
67
- Pry::WrappedModule(Host::ForeverAlone).source_location.should == nil
68
- end
69
- end
70
-
71
- describe "source" do
72
- it 'should return primary candidates source by default' do
73
- wm = Pry::WrappedModule(Host::CandidateTest)
74
- wm.source.should == wm.candidate(0).source
75
- end
76
-
77
- it 'should return source for highest ranked candidate' do
78
- Pry::WrappedModule(Host::CandidateTest).candidate(0).source.should =~ /test1/
79
- end
80
-
81
- it 'should return source for second ranked candidate' do
82
- Pry::WrappedModule(Host::CandidateTest).candidate(1).source.should =~ /test4/
83
- end
84
-
85
- it 'should return source for third ranked candidate' do
86
- Pry::WrappedModule(Host::CandidateTest).candidate(2).source.should =~ /test6/
87
- end
88
- end
89
-
90
- describe "doc" do
91
- it 'should return primary candidates doc by default' do
92
- wm = Pry::WrappedModule(Host::CandidateTest)
93
- wm.doc.should == wm.candidate(0).doc
94
- end
95
-
96
- it 'should return doc for highest ranked candidate' do
97
- Pry::WrappedModule(Host::CandidateTest).candidate(0).doc.should =~ /rank 0/
98
- end
99
-
100
- it 'should return doc for second ranked candidate' do
101
- Pry::WrappedModule(Host::CandidateTest).candidate(1).doc.should =~ /rank 1/
102
- end
103
-
104
- it 'should return doc for third ranked candidate' do
105
- Pry::WrappedModule(Host::CandidateTest).candidate(2).doc.should =~ /rank 2/
106
- end
107
- end
108
-
109
- after do
110
- Object.remove_const(:Host)
111
- end
112
- end
113
-
114
- describe ".method_prefix" do
115
- before do
116
- Foo = Class.new
117
- @foo = Foo.new
118
- end
119
-
120
- after do
121
- Object.remove_const(:Foo)
122
- end
123
-
124
- it "should return Foo# for normal classes" do
125
- Pry::WrappedModule.new(Foo).method_prefix.should == "Foo#"
126
- end
127
-
128
- it "should return Bar# for modules" do
129
- Pry::WrappedModule.new(Kernel).method_prefix.should == "Kernel#"
130
- end
131
-
132
- it "should return Foo. for singleton classes of classes" do
133
- Pry::WrappedModule.new(class << Foo; self; end).method_prefix.should == "Foo."
134
- end
135
-
136
- describe "of singleton classes of objects" do
137
- Pry::WrappedModule.new(class << @foo; self; end).method_prefix.should == "self."
138
- end
139
-
140
- describe "of anonymous classes should not be empty" do
141
- Pry::WrappedModule.new(Class.new).method_prefix.should =~ /#<Class:.*>#/
142
- end
143
-
144
- describe "of singleton classes of anonymous classes should not be empty" do
145
- Pry::WrappedModule.new(class << Class.new; self; end).method_prefix.should =~ /#<Class:.*>./
146
- end
147
- end
148
-
149
- describe ".singleton_class?" do
150
- it "should be true for singleton classes" do
151
- Pry::WrappedModule.new(class << ""; self; end).singleton_class?.should == true
152
- end
153
-
154
- it "should be false for normal classes" do
155
- Pry::WrappedModule.new(Class.new).singleton_class?.should == false
156
- end
157
-
158
- it "should be false for modules" do
159
- Pry::WrappedModule.new(Module.new).singleton_class?.should == false
160
- end
161
- end
162
-
163
- describe ".singleton_instance" do
164
- it "should raise an exception when called on a non-singleton-class" do
165
- lambda{ Pry::WrappedModule.new(Class).singleton_instance }.should.raise ArgumentError
166
- end
167
-
168
- it "should return the attached object" do
169
- Pry::WrappedModule.new(class << "hi"; self; end).singleton_instance.should == "hi"
170
- Pry::WrappedModule.new(class << Object; self; end).singleton_instance.should.equal?(Object)
171
- end
172
- end
173
- end
174
-
@@ -1,2 +0,0 @@
1
- TEST_RC = [] if !Object.const_defined?(:TEST_RC)
2
- TEST_RC << 0
@@ -1,2 +0,0 @@
1
- TEST_BEFORE_RAISE = 1
2
- raise "messin with ya"
@@ -1,397 +0,0 @@
1
- Customizing Pry
2
- ---------------
3
-
4
- Pry supports customization of the input, the output, the commands,
5
- the hooks, the prompt, and the 'print' object (the "P" in REPL).
6
-
7
- Global customization, which applies to all Pry sessions, is done
8
- through invoking class accessors on the `Pry` class, the accessors
9
- are:
10
-
11
- * `Pry.input=`
12
- * `Pry.output=`
13
- * `Pry.commands=`
14
- * `Pry.hooks=`
15
- * `Pry.prompt=`
16
- * `Pry.print=`
17
-
18
- Local customization (applied to a single Pry session) is done by
19
- passing config hash options to `Pry.start()` or to `Pry.new()`; also the
20
- same accessors as described above for the `Pry` class exist for a
21
- Pry instance so that customization can occur at runtime.
22
-
23
- ### Input
24
-
25
- For input Pry accepts any object that implements the `readline` method. This
26
- includes `IO` objects, `StringIO`, `Readline`, `File` and custom objects. Pry
27
- initially defaults to using `Readline` for input.
28
-
29
- #### Example: Setting global input
30
-
31
- Setting Pry's global input causes all subsequent Pry instances to use
32
- this input by default:
33
-
34
- Pry.input = StringIO.new("@x = 10\nexit")
35
- Object.pry
36
-
37
- Object.instance_variable_get(:@x) #=> 10
38
-
39
- The above will execute the code in the `StringIO`
40
- non-interactively. It gets all the input it needs from the `StringIO`
41
- and then exits the Pry session. Note it is important to end the
42
- session with 'exit' if you are running non-interactively or the Pry
43
- session will hang as it loops indefinitely awaiting new input.
44
-
45
- #### Example: Setting input for a specific session
46
-
47
- The settings for a specific session override the global settings
48
- (discussed above). There are two ways to set input for a specific pry session: At the
49
- point the session is started, or within the session itself (at runtime):
50
-
51
- ##### At session start
52
-
53
- Pry.start(Object, :input => StringIO.new("@x = 10\nexit"))
54
- Object.instance_variable_get(:@x) #=> 10
55
-
56
- ##### At runtime
57
-
58
- If you want to set the input object within the session itself you use
59
- the special `_pry_` local variable which represents the Pry instance
60
- managing the current session; inside the session we type:
61
-
62
- _pry_.input = StringIO.new("@x = 10\nexit")
63
-
64
- Note we can also set the input object for the parent Pry session (if
65
- the current session is nested) like so:
66
-
67
- _pry_.parent.input = StringIO.new("@x = 10\nexit")
68
-
69
- ### Output
70
-
71
- For output Pry accepts any object that implements the `puts` method. This
72
- includes `IO` objects, `StringIO`, `File` and custom objects. Pry initially
73
- defaults to using `$stdout` for output.
74
-
75
- #### Example: Setting global output
76
-
77
- Setting Pry's global output causes all subsequent Pry instances to use
78
- this output by default:
79
-
80
- Pry.output = StringIO.new
81
-
82
- #### Example: Setting output for a specific session
83
-
84
- As per Input, given above, we set the local output as follows:
85
-
86
- ##### At session start
87
-
88
- Pry.start(Object, :output => StringIO.new("@x = 10\nexit"))
89
-
90
- ##### At runtime
91
-
92
- _pry_.output = StringIO.new
93
-
94
- ### Commands
95
-
96
- Pry commands are not methods; they are commands that are intercepted
97
- and executed before a Ruby eval takes place. Pry comes with a default
98
- command set (`Pry::Commands`), but these commands can be augmented or overriden by
99
- user-specified ones.
100
-
101
- The Pry command API is quite sophisticated supporting features such as:
102
- command set inheritance, importing of specific commands from another
103
- command set, deletion of commands, calling of commands within other
104
- commands, and so on.
105
-
106
- A valid Pry command object must inherit from
107
- `Pry::CommandBase` (or one of its subclasses) and use the special command API:
108
-
109
- #### Example: Defining a command object and setting it globally
110
-
111
- class MyCommands < Pry::CommandBase
112
- command "greet", "Greet the user." do |name, age|
113
- output.puts "Hello #{name.capitalize}, how does it feel being #{age}?"
114
- end
115
- end
116
-
117
- Pry.commands = MyCommands
118
-
119
- Then inside a pry session:
120
-
121
- pry(main)> greet john 9
122
- Hello John, how does it feel being 9?
123
- => nil
124
-
125
- #### Example: Using a command object in a specific session
126
-
127
- As in the case of `input` and `output`:
128
-
129
- ##### At session start:
130
-
131
- Pry.start(self, :commands => MyCommands)
132
-
133
- ##### At runtime:
134
-
135
- _pry_.commands = MyCommands
136
-
137
- #### The command API
138
-
139
- The command API is defined by the `Pry::CommandBase` class (hence why
140
- all commands must inherit from it or a subclass). The API works as follows:
141
-
142
- ##### `command` method
143
-
144
- The `command` method defines a new command, its parameter is the
145
- name of the command and an optional second parameter is a description of
146
- the command.
147
-
148
- The associated block defines the action to be performed. The number of
149
- parameters in the block determine the number of parameters that will
150
- be sent to the command (from the Pry prompt) when it is invoked. Note
151
- that all parameters that are received will be strings; if a parameter
152
- is not received it will be set to `nil`.
153
-
154
- command "hello" do |x, y, z|
155
- puts "hello there #{x}, #{y}, and #{z}!"
156
- end
157
-
158
- Command aliases can also be defined - simply use an array of strings
159
- for the command name - all these strings will be valid names for the
160
- command.
161
-
162
- command ["ls", "dir"], "show a list of local vars" do
163
- output.puts target.eval("local_variables")
164
- end
165
-
166
- ##### `delete` method
167
-
168
- The `delete` method deletes a command or a group of commands. It
169
- can be useful when inheriting from another command set and you wish
170
- to keep only a portion of the inherited commands.
171
-
172
- class MyCommands < Pry::Commands
173
- delete "show_method", "show_imethod"
174
- end
175
-
176
- ##### `import_from` method
177
-
178
- The `import_from` method enables you to specifically select which
179
- commands will be copied across from another command set, useful when
180
- you only want a small number of commands and so inheriting and then
181
- deleting would be inefficient. The first parameter to `import_from`
182
- is the class to import from and the other paramters are the names of
183
- the commands to import:
184
-
185
- class MyCommands < Pry::CommandBase
186
- import_from Pry::Commands, "ls", "status", "!"
187
- end
188
-
189
- ##### `run` method
190
-
191
- The `run` command invokes one command from within another.
192
- The first parameter is the name of the command to invoke
193
- and the remainder of the parameters will be passed on to the command
194
- being invoked:
195
-
196
- class MyCommands < Pry::Commands
197
- command "ls_with_hello" do
198
- output.puts "hello!"
199
- run "ls"
200
- end
201
- end
202
-
203
- ##### `alias_command` method
204
-
205
- The `alias_command` method creates an alias of a command. The first
206
- parameter is the name of the new command, the second parameter is the
207
- name of the command to be aliased; an optional third parameter is the
208
- description to use for the alias. If no description is provided then
209
- the description of the original command is used.
210
-
211
- class MyCommands < Pry::Commands
212
- alias_command "help2", "help", "An alias of help"
213
- end
214
-
215
- ##### `desc` method
216
-
217
- The `desc` method is used to give a command a new description. The
218
- first parameter is the name of the command, the second parameter is
219
- the description.
220
-
221
- class MyCommands < Pry::Commands
222
- desc "ls", "a new description"
223
- end
224
-
225
- #### Utility methods for commands
226
-
227
- All commands can access the special `output` and `target` methods. The
228
- `output` method returns the `output` object for the active pry session.
229
- Ensuring that your commands invoke `puts` on this rather than using
230
- the top-level `puts` will ensure that all your session output goes to
231
- the same place.
232
-
233
- The `target` method returns the `Binding` object the Pry session is currently
234
- active on - useful when your commands need to manipulate or examine
235
- the state of the object. E.g, the "ls" command is implemented as follows
236
-
237
- command "ls" do
238
- output.puts target.eval("local_variables + instance_variables").inspect
239
- end
240
-
241
- #### The opts hash
242
-
243
- These are miscellaneous variables that may be useful to your commands:
244
-
245
- * `opts[:val]` - The line of input that invoked the command.
246
- * `opts[:eval_string]` - The cumulative lines of input for multi-line input.
247
- * `opts[:nesting]` - Lowlevel session nesting information.
248
- * `opts[:commands]` - Lowlevel data of all Pry commands.
249
-
250
- (see commands.rb for examples of how some of these options are used)
251
-
252
- #### The `help` command
253
-
254
- The `Pry::CommandBase` class automatically defines a `help` command
255
- for you. Typing `help` in a Pry session will show a list of commands
256
- to the user followed by their descriptions. Passing a parameter to
257
- `help` with the command name will just return the description of that
258
- specific command. If a description is left out it will automatically
259
- be given the description "No description.".
260
-
261
- If the description is explicitly set to `""` then this command will
262
- not be displayed in `help`.
263
-
264
- ### Hooks
265
-
266
- Currently Pry supports just two hooks: `before_session` and
267
- `after_session`. These hooks are invoked before a Pry session starts
268
- and after a session ends respectively. The default hooks used are
269
- stored in the `Pry::DEFAULT_HOOKS` and just output the text `"Beginning
270
- Pry session for <obj>"` and `"Ending Pry session for <obj>"`.
271
-
272
- #### Example: Setting global hooks
273
-
274
- All subsequent Pry instances will use these hooks as default:
275
-
276
- Pry.hooks = {
277
- :before_session => proc { |out, obj| out.puts "Opened #{obj}" },
278
- :after_session => proc { |out, obj| out.puts "Closed #{obj}" }
279
- }
280
-
281
- 5.pry
282
-
283
- Inside the session:
284
-
285
- Opened 5
286
- pry(5)> exit
287
- Closed 5
288
-
289
- Note that the `before_session` and `after_session` procs receive the
290
- current session's output object and session receiver as parameters.
291
-
292
- #### Example: Setting hooks for a specific session
293
-
294
- Like all the other customization options, the global default (as
295
- explained above) can be overriden for a specific session, either at
296
- session start or during runtime.
297
-
298
- ##### At session start
299
-
300
- Pry.start(self, :hooks => { :before_session => proc { puts "hello world!" },
301
- :after_session => proc { puts "goodbye world!" }
302
- })
303
-
304
- ##### At runtime
305
-
306
- _pry_.hooks = { :before_session => proc { puts "puts "hello world!" } }
307
-
308
- ### Prompts
309
-
310
- The Pry prompt is used by `Readline` and other input objects that
311
- accept a prompt. Pry can accept two prompt-types for every prompt; the
312
- 'main prompt' and the 'wait prompt'. The main prompt is always used
313
- for the first line of input; the wait prompt is used in multi-line
314
- input to indicate that the current expression is incomplete and more lines of
315
- input are required. The default Prompt used by Pry is stored in the
316
- `Pry::DEFAULT_PROMPT` constant.
317
-
318
- A valid Pry prompt is either a single `Proc` object or a two element
319
- array of `Proc` objects. When an array is used the first element is
320
- the 'main prompt' and the last element is the 'wait prompt'. When a
321
- single `Proc` object is used it will be used for both the main prompt
322
- and the wait prompt.
323
-
324
- #### Example: Setting global prompt
325
-
326
- The prompt `Proc` objects are passed the receiver of the Pry session
327
- and the nesting level of that session as parameters (they can simply
328
- ignore these if they do not need them).
329
-
330
- # Using one proc for both main and wait prompts
331
- Pry.prompt = proc { |obj, nest_level| "#{obj}:#{nest_level}> " }
332
-
333
- # Alternatively, provide two procs; one for main and one for wait
334
- Pry.prompt = [ proc { "ENTER INPUT> " }, proc { "MORE INPUT REQUIRED!* " }]
335
-
336
- #### Example: Setting the prompt for a specific session
337
-
338
- ##### At session start
339
-
340
- Pry.start(self, :prompt => [proc { "ENTER INPUT> " },
341
- proc { "MORE INPUT REQUIRED!* " }])
342
-
343
- ##### At runtime
344
-
345
- _pry_.prompt = [proc { "ENTER INPUT> " },
346
- proc { "MORE INPUT REQUIRED!* " }]
347
-
348
- ### Print
349
-
350
- The Print phase of Pry's READ-EVAL-PRINT-LOOP can be customized. The
351
- default action is stored in the `Pry::DEFAULT_PRINT` constant and it
352
- simply outputs the value of the current expression preceded by a `=>` (or the first
353
- line of the backtrace if the value is an `Exception` object.)
354
-
355
- The print object should be a `Proc` and the parameters passed to the
356
- `Proc` are the output object for the current session and the 'value'
357
- returned by the current expression.
358
-
359
- #### Example: Setting global print object
360
-
361
- Let's define a print object that displays the full backtrace of any
362
- exception and precedes the output of a value by the text `"Output is: "`:
363
-
364
- Pry.print = proc do |output, value|
365
- case value
366
- when Exception
367
- output.puts value.backtrace
368
- else
369
- output.puts "Output is: #{value}"
370
- end
371
- end
372
-
373
- #### Example: Setting the print object for a specific session
374
-
375
- ##### At session start
376
-
377
- Pry.start(self, :print => proc do |output, value|
378
- case value
379
- when Exception
380
- output.puts value.backtrace
381
- else
382
- output.puts "Output is: #{value.inspect}"
383
- end
384
- end)
385
-
386
- ##### At runtime
387
-
388
- _pry_.print = proc do |output, value|
389
- case value
390
- when Exception
391
- output.puts value.backtrace
392
- else
393
- output.puts "Output is: #{value.inspect}"
394
- end
395
- end
396
-
397
- [Back to front page of documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)