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,65 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::HistoryArray do
4
- before do
5
- @array = Pry::HistoryArray.new 10
6
- end
7
-
8
- it 'should have a maximum size specifed at creation time' do
9
- @array.max_size.should == 10
10
- end
11
-
12
- it 'should be able to be added objects to' do
13
- @array << 1 << 2 << 3
14
- @array.size.should == 3
15
- @array.to_a.should == [1, 2, 3]
16
- end
17
-
18
- it 'should be able to access single elements' do
19
- @array << 1 << 2 << 3
20
- @array[2].should == 3
21
- end
22
-
23
- it 'should be able to access negative indices' do
24
- @array << 1 << 2 << 3
25
- @array[-1].should == 3
26
- end
27
-
28
- it 'should be able to access ranges' do
29
- @array << 1 << 2 << 3 << 4
30
- @array[1..2].should == [2, 3]
31
- end
32
-
33
- it 'should be able to access ranges starting from a negative index' do
34
- @array << 1 << 2 << 3 << 4
35
- @array[-2..3].should == [3, 4]
36
- end
37
-
38
- it 'should be able to access ranges ending at a negative index' do
39
- @array << 1 << 2 << 3 << 4
40
- @array[2..-1].should == [3, 4]
41
- end
42
-
43
- it 'should be able to access ranges using only negative indices' do
44
- @array << 1 << 2 << 3 << 4
45
- @array[-2..-1].should == [3, 4]
46
- end
47
-
48
- it 'should be able to use range where end is excluded' do
49
- @array << 1 << 2 << 3 << 4
50
- @array[-2...-1].should == [3]
51
- end
52
-
53
- it 'should be able to access slices using a size' do
54
- @array << 1 << 2 << 3 << 4
55
- @array[-3, 2].should == [2, 3]
56
- end
57
-
58
- it 'should remove older entries' do
59
- 11.times { |n| @array << n }
60
-
61
- @array[0].should == nil
62
- @array[1].should == 1
63
- @array[10].should == 10
64
- end
65
- end
@@ -1,521 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::Hooks do
4
- before do
5
- @hooks = Pry::Hooks.new
6
- end
7
-
8
- describe "adding a new hook" do
9
- it 'should not execute hook while adding it' do
10
- run = false
11
- @hooks.add_hook(:test_hook, :my_name) { run = true }
12
- run.should == false
13
- end
14
-
15
- it 'should not allow adding of a hook with a duplicate name' do
16
- @hooks.add_hook(:test_hook, :my_name) {}
17
-
18
- lambda { @hooks.add_hook(:test_hook, :my_name) {} }.should.raise ArgumentError
19
- end
20
-
21
- it 'should create a new hook with a block' do
22
- @hooks.add_hook(:test_hook, :my_name) { }
23
- @hooks.hook_count(:test_hook).should == 1
24
- end
25
-
26
- it 'should create a new hook with a callable' do
27
- @hooks.add_hook(:test_hook, :my_name, proc { })
28
- @hooks.hook_count(:test_hook).should == 1
29
- end
30
-
31
- it 'should use block if given both block and callable' do
32
- run = false
33
- foo = false
34
- @hooks.add_hook(:test_hook, :my_name, proc { foo = true }) { run = true }
35
- @hooks.hook_count(:test_hook).should == 1
36
- @hooks.exec_hook(:test_hook)
37
- run.should == true
38
- foo.should == false
39
- end
40
-
41
- it 'should raise if not given a block or any other object' do
42
- lambda { @hooks.add_hook(:test_hook, :my_name) }.should.raise ArgumentError
43
- end
44
-
45
- it 'should create multiple hooks for an event' do
46
- @hooks.add_hook(:test_hook, :my_name) {}
47
- @hooks.add_hook(:test_hook, :my_name2) {}
48
- @hooks.hook_count(:test_hook).should == 2
49
- end
50
-
51
- it 'should return a count of 0 for an empty hook' do
52
- @hooks.hook_count(:test_hook).should == 0
53
- end
54
- end
55
-
56
- describe "Pry::Hooks#merge" do
57
- describe "merge!" do
58
- it 'should merge in the Pry::Hooks' do
59
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
60
- h2 = Pry::Hooks.new
61
-
62
- h2.merge!(h1)
63
- h2.get_hook(:test_hook, :testing).should == h1.get_hook(:test_hook, :testing)
64
- end
65
-
66
- it 'should not share merged elements with original' do
67
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
68
- h2 = Pry::Hooks.new
69
-
70
- h2.merge!(h1)
71
- h2.add_hook(:test_hook, :testing2) {}
72
- h2.get_hook(:test_hook, :testing2).should.not == h1.get_hook(:test_hook, :testing2)
73
- end
74
-
75
- it 'should NOT overwrite hooks belonging to shared event in receiver' do
76
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
77
- callable = proc {}
78
- h2 = Pry::Hooks.new.add_hook(:test_hook, :testing2, callable)
79
-
80
- h2.merge!(h1)
81
- h2.get_hook(:test_hook, :testing2).should == callable
82
- end
83
-
84
- it 'should overwrite identical hook in receiver' do
85
- callable1 = proc { :one }
86
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing, callable1)
87
- callable2 = proc { :two }
88
- h2 = Pry::Hooks.new.add_hook(:test_hook, :testing, callable2)
89
-
90
- h2.merge!(h1)
91
- h2.get_hook(:test_hook, :testing).should == callable1
92
- h2.hook_count(:test_hook).should == 1
93
- end
94
-
95
- it 'should preserve hook order' do
96
- name = ""
97
- h1 = Pry::Hooks.new
98
- h1.add_hook(:test_hook, :testing3) { name << "h" }
99
- h1.add_hook(:test_hook, :testing4) { name << "n" }
100
-
101
- h2 = Pry::Hooks.new
102
- h2.add_hook(:test_hook, :testing1) { name << "j" }
103
- h2.add_hook(:test_hook, :testing2) { name << "o" }
104
-
105
- h2.merge!(h1)
106
- h2.exec_hook(:test_hook)
107
-
108
- name.should == "john"
109
- end
110
-
111
- describe "merge" do
112
- it 'should return a fresh, independent instance' do
113
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
114
- h2 = Pry::Hooks.new
115
-
116
- h3 = h2.merge(h1)
117
- h3.should.not == h1
118
- h3.should.not == h2
119
- end
120
-
121
- it 'should contain hooks from original instance' do
122
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
123
- h2 = Pry::Hooks.new.add_hook(:test_hook2, :testing) {}
124
-
125
- h3 = h2.merge(h1)
126
- h3.get_hook(:test_hook, :testing).should == h1.get_hook(:test_hook, :testing)
127
- h3.get_hook(:test_hook2, :testing).should == h2.get_hook(:test_hook2, :testing)
128
- end
129
-
130
- it 'should not affect original instances when new hooks are added' do
131
- h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
132
- h2 = Pry::Hooks.new.add_hook(:test_hook2, :testing) {}
133
-
134
- h3 = h2.merge(h1)
135
- h3.add_hook(:test_hook3, :testing) {}
136
-
137
- h1.get_hook(:test_hook3, :testing).should == nil
138
- h2.get_hook(:test_hook3, :testing).should == nil
139
- end
140
- end
141
-
142
- end
143
- end
144
-
145
- describe "dupping a Pry::Hooks instance" do
146
- it 'should share hooks with original' do
147
- @hooks.add_hook(:test_hook, :testing) do
148
- :none_such
149
- end
150
-
151
- hooks_dup = @hooks.dup
152
- hooks_dup.get_hook(:test_hook, :testing).should == @hooks.get_hook(:test_hook, :testing)
153
- end
154
-
155
- it 'adding a new event to dupped instance should not affect original' do
156
- @hooks.add_hook(:test_hook, :testing) { :none_such }
157
- hooks_dup = @hooks.dup
158
-
159
- hooks_dup.add_hook(:other_test_hook, :testing) { :okay_man }
160
-
161
- hooks_dup.get_hook(:other_test_hook, :testing).should.not == @hooks.get_hook(:other_test_hook, :testing)
162
- end
163
-
164
- it 'adding a new hook to dupped instance should not affect original' do
165
- @hooks.add_hook(:test_hook, :testing) { :none_such }
166
- hooks_dup = @hooks.dup
167
-
168
- hooks_dup.add_hook(:test_hook, :testing2) { :okay_man }
169
-
170
- hooks_dup.get_hook(:test_hook, :testing2).should.not == @hooks.get_hook(:test_hook, :testing2)
171
- end
172
-
173
- end
174
-
175
- describe "getting hooks" do
176
- describe "get_hook" do
177
- it 'should return the correct requested hook' do
178
- run = false
179
- fun = false
180
- @hooks.add_hook(:test_hook, :my_name) { run = true }
181
- @hooks.add_hook(:test_hook, :my_name2) { fun = true }
182
- @hooks.get_hook(:test_hook, :my_name).call
183
- run.should == true
184
- fun.should == false
185
- end
186
-
187
- it 'should return nil if hook does not exist' do
188
- @hooks.get_hook(:test_hook, :my_name).should == nil
189
- end
190
- end
191
-
192
- describe "get_hooks" do
193
- it 'should return a hash of hook names/hook functions for an event' do
194
- hook1 = proc { 1 }
195
- hook2 = proc { 2 }
196
- @hooks.add_hook(:test_hook, :my_name1, hook1)
197
- @hooks.add_hook(:test_hook, :my_name2, hook2)
198
- hash = @hooks.get_hooks(:test_hook)
199
- hash.size.should == 2
200
- hash[:my_name1].should == hook1
201
- hash[:my_name2].should == hook2
202
- end
203
-
204
- it 'should return an empty hash if no hooks defined' do
205
- @hooks.get_hooks(:test_hook).should == {}
206
- end
207
- end
208
- end
209
-
210
- describe "clearing all hooks for an event" do
211
- it 'should clear all hooks' do
212
- @hooks.add_hook(:test_hook, :my_name) { }
213
- @hooks.add_hook(:test_hook, :my_name2) { }
214
- @hooks.add_hook(:test_hook, :my_name3) { }
215
- @hooks.clear(:test_hook)
216
- @hooks.hook_count(:test_hook).should == 0
217
- end
218
- end
219
-
220
- describe "deleting a hook" do
221
- it 'should successfully delete a hook' do
222
- @hooks.add_hook(:test_hook, :my_name) {}
223
- @hooks.delete_hook(:test_hook, :my_name)
224
- @hooks.hook_count(:test_hook).should == 0
225
- end
226
-
227
- it 'should return the deleted hook' do
228
- run = false
229
- @hooks.add_hook(:test_hook, :my_name) { run = true }
230
- @hooks.delete_hook(:test_hook, :my_name).call
231
- run.should == true
232
- end
233
-
234
- it 'should return nil if hook does not exist' do
235
- @hooks.delete_hook(:test_hook, :my_name).should == nil
236
- end
237
- end
238
-
239
- describe "executing a hook" do
240
- it 'should execute block hook' do
241
- run = false
242
- @hooks.add_hook(:test_hook, :my_name) { run = true }
243
- @hooks.exec_hook(:test_hook)
244
- run.should == true
245
- end
246
-
247
- it 'should execute proc hook' do
248
- run = false
249
- @hooks.add_hook(:test_hook, :my_name, proc { run = true })
250
- @hooks.exec_hook(:test_hook)
251
- run.should == true
252
- end
253
-
254
- it 'should execute a general callable hook' do
255
- callable = Object.new.tap do |obj|
256
- obj.instance_variable_set(:@test_var, nil)
257
- class << obj
258
- attr_accessor :test_var
259
- def call() @test_var = true; end
260
- end
261
- end
262
-
263
- @hooks.add_hook(:test_hook, :my_name, callable)
264
- @hooks.exec_hook(:test_hook)
265
- callable.test_var.should == true
266
- end
267
-
268
- it 'should execute all hooks for an event if more than one is defined' do
269
- x = nil
270
- y = nil
271
- @hooks.add_hook(:test_hook, :my_name1) { y = true }
272
- @hooks.add_hook(:test_hook, :my_name2) { x = true }
273
- @hooks.exec_hook(:test_hook)
274
- x.should == true
275
- y.should == true
276
- end
277
-
278
- it 'should execute hooks in order' do
279
- array = []
280
- @hooks.add_hook(:test_hook, :my_name1) { array << 1 }
281
- @hooks.add_hook(:test_hook, :my_name2) { array << 2 }
282
- @hooks.add_hook(:test_hook, :my_name3) { array << 3 }
283
- @hooks.exec_hook(:test_hook)
284
- array.should == [1, 2, 3]
285
- end
286
-
287
- it 'return value of exec_hook should be that of last executed hook' do
288
- @hooks.add_hook(:test_hook, :my_name1) { 1 }
289
- @hooks.add_hook(:test_hook, :my_name2) { 2 }
290
- @hooks.add_hook(:test_hook, :my_name3) { 3 }
291
- @hooks.exec_hook(:test_hook).should == 3
292
- end
293
-
294
- it 'should add exceptions to the errors array' do
295
- @hooks.add_hook(:test_hook, :foo1) { raise 'one' }
296
- @hooks.add_hook(:test_hook, :foo2) { raise 'two' }
297
- @hooks.add_hook(:test_hook, :foo3) { raise 'three' }
298
- @hooks.exec_hook(:test_hook)
299
- @hooks.errors.map(&:message).should == ['one', 'two', 'three']
300
- end
301
-
302
- it 'should return the last exception raised as the return value' do
303
- @hooks.add_hook(:test_hook, :foo1) { raise 'one' }
304
- @hooks.add_hook(:test_hook, :foo2) { raise 'two' }
305
- @hooks.add_hook(:test_hook, :foo3) { raise 'three' }
306
- @hooks.exec_hook(:test_hook).should == @hooks.errors.last
307
- end
308
- end
309
-
310
- describe "integration tests" do
311
- describe "when_started hook" do
312
- it 'should yield options to the hook' do
313
- options = nil
314
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| options = opt }
315
-
316
- redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
317
- Pry.start binding, :hello => :baby
318
- end
319
- options[:hello].should == :baby
320
-
321
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
322
- end
323
-
324
- describe "target" do
325
-
326
- it 'should yield the target, as a binding ' do
327
- b = nil
328
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| b = target }
329
-
330
- redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
331
- Pry.start 5, :hello => :baby
332
- end
333
-
334
- b.is_a?(Binding).should == true
335
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
336
- end
337
-
338
- it 'should yield the target to the hook' do
339
- b = nil
340
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| b = target }
341
-
342
- redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
343
- Pry.start 5, :hello => :baby
344
- end
345
-
346
- b.eval('self').should == 5
347
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
348
- end
349
- end
350
-
351
- it 'should allow overriding of target (and binding_stack)' do
352
- options = nil
353
- o = Object.new
354
- class << o; attr_accessor :value; end
355
-
356
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _pry_| _pry_.binding_stack = [Pry.binding_for(o)] }
357
-
358
- redirect_pry_io(InputTester.new("@value = true","exit-all")) do
359
- Pry.start binding, :hello => :baby
360
- end
361
-
362
- o.value.should == true
363
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
364
- end
365
-
366
- end
367
-
368
- describe "after_session hook" do
369
- it 'should always run, even if uncaught exception bubbles out of repl' do
370
- o = OpenStruct.new
371
- o.great_escape = Class.new(StandardError)
372
-
373
- old_ew = Pry.config.exception_whitelist
374
- Pry.config.exception_whitelist << o.great_escape
375
-
376
- array = [1, 2, 3, 4, 5]
377
-
378
- begin
379
- redirect_pry_io(StringIO.new("raise great_escape"), out=StringIO.new) do
380
- Pry.start o, :hooks => Pry::Hooks.new.add_hook(:after_session, :cleanup) { array = nil }
381
- end
382
- rescue => ex
383
- exception = ex
384
- end
385
-
386
- # ensure that an exception really was raised and it broke out
387
- # of the repl
388
- exception.is_a?(o.great_escape).should == true
389
-
390
- # check that after_session hook ran
391
- array.should == nil
392
-
393
- # cleanup after test
394
- Pry.config.exception_whitelist = old_ew
395
- end
396
-
397
- describe "before_eval hook" do
398
- describe "modifying input code" do
399
- it 'should replace input code with code determined by hook' do
400
- hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
401
- redirect_pry_io(InputTester.new(":jemima", "exit-all"), out = StringIO.new) do
402
- Pry.start(self, :hooks => hooks)
403
- end
404
- out.string.should =~ /little_duck/
405
- out.string.should.not =~ /jemima/
406
- end
407
-
408
- it 'should not interfere with command processing when replacing input code' do
409
- commands = Pry::CommandSet.new do
410
- import_from Pry::Commands, "exit-all"
411
-
412
- command "how-do-you-like-your-blue-eyed-boy-now-mister-death" do
413
- output.puts "in hours of bitterness i imagine balls of sapphire, of metal"
414
- end
415
- end
416
-
417
- hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
418
- redirect_pry_io(InputTester.new("how-do-you-like-your-blue-eyed-boy-now-mister-death", "exit-all"), out = StringIO.new) do
419
- Pry.start(self, :hooks => hooks, :commands => commands)
420
- end
421
- out.string.should =~ /in hours of bitterness i imagine balls of sapphire, of metal/
422
- out.string.should.not =~ /little_duck/
423
- end
424
- end
425
-
426
- end
427
-
428
- describe "exceptions" do
429
- before do
430
- Pry.config.hooks.add_hook(:after_eval, :baddums){ raise "Baddums" }
431
- Pry.config.hooks.add_hook(:after_eval, :simbads){ raise "Simbads" }
432
- end
433
-
434
- after do
435
- Pry.config.hooks.delete_hook(:after_eval, :baddums)
436
- Pry.config.hooks.delete_hook(:after_eval, :simbads)
437
- end
438
- it "should not raise exceptions" do
439
- lambda{
440
- mock_pry("1", "2", "3")
441
- }.should.not.raise
442
- end
443
-
444
- it "should print out a notice for each exception raised" do
445
- mock_pry("1").should =~ /after_eval hook failed: RuntimeError: Baddums\n.*after_eval hook failed: RuntimeError: Simbads/m
446
- end
447
- end
448
- end
449
- end
450
-
451
- describe "anonymous hooks" do
452
- it 'should allow adding of hook without a name' do
453
- @hooks.add_hook(:test_hook, nil) {}
454
- @hooks.hook_count(:test_hook).should == 1
455
- end
456
-
457
- it 'should only allow one anonymous hook to exist' do
458
- @hooks.add_hook(:test_hook, nil) { }
459
- @hooks.add_hook(:test_hook, nil) { }
460
- @hooks.hook_count(:test_hook).should == 1
461
- end
462
-
463
- it 'should execute most recently added anonymous hook' do
464
- x = nil
465
- y = nil
466
- @hooks.add_hook(:test_hook, nil) { y = 1 }
467
- @hooks.add_hook(:test_hook, nil) { x = 2 }
468
- @hooks.exec_hook(:test_hook)
469
- y.should == nil
470
- x.should == 2
471
- end
472
- end
473
-
474
- describe "deprecated hash-based API" do
475
- after do
476
- Pry.config.hooks.clear_all if Pry.config.hooks
477
- end
478
-
479
- describe "Pry.config.hooks" do
480
- it 'should allow a hash-assignment' do
481
- Pry.config.hooks = { :before_session => proc { :hello } }
482
- Pry.config.hooks.get_hook(:before_session, nil).call.should == :hello
483
- end
484
-
485
- describe "Pry.config.hooks[]" do
486
- it 'should return the only anonymous hook' do
487
- Pry.config.hooks = { :before_session => proc { :hello } }
488
- Pry.config.hooks[:before_session].call.should == :hello
489
- end
490
-
491
- it 'should add an anonymous hook when using Pry.config.hooks[]=' do
492
- Pry.config.hooks[:before_session] = proc { :bing }
493
- Pry.config.hooks.hook_count(:before_session).should == 1
494
- end
495
-
496
- it 'should add overwrite previous anonymous hooks with new one when calling Pry.config.hooks[]= multiple times' do
497
- x = nil
498
- Pry.config.hooks[:before_session] = proc { x = 1 }
499
- Pry.config.hooks[:before_session] = proc { x = 2 }
500
-
501
- Pry.config.hooks.exec_hook(:before_session)
502
- Pry.config.hooks.hook_count(:before_session).should == 1
503
- x.should == 2
504
- end
505
- end
506
- end
507
-
508
- describe "Pry.start" do
509
- it 'should accept a hash for :hooks parameter' do
510
-
511
- redirect_pry_io(InputTester.new("exit-all"), out=StringIO.new) do
512
- Pry.start binding, :hooks => { :before_session => proc { |output, _, _| output.puts 'hello friend' } }
513
- end
514
-
515
- out.string.should =~ /hello friend/
516
- end
517
-
518
- end
519
- end
520
-
521
- end