pry 0.9.12.6-i386-mswin32 → 0.10.0-i386-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +19 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +6 -7
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  22. data/lib/pry/commands/cd.rb +14 -3
  23. data/lib/pry/commands/change_inspector.rb +27 -0
  24. data/lib/pry/commands/change_prompt.rb +26 -0
  25. data/lib/pry/commands/code_collector.rb +4 -4
  26. data/lib/pry/commands/easter_eggs.rb +3 -3
  27. data/lib/pry/commands/edit.rb +10 -22
  28. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  29. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  30. data/lib/pry/commands/exit_program.rb +0 -1
  31. data/lib/pry/commands/find_method.rb +16 -22
  32. data/lib/pry/commands/gem_install.rb +5 -2
  33. data/lib/pry/commands/gem_open.rb +1 -1
  34. data/lib/pry/commands/gist.rb +10 -11
  35. data/lib/pry/commands/help.rb +14 -14
  36. data/lib/pry/commands/hist.rb +27 -8
  37. data/lib/pry/commands/install_command.rb +14 -12
  38. data/lib/pry/commands/list_inspectors.rb +35 -0
  39. data/lib/pry/commands/list_prompts.rb +35 -0
  40. data/lib/pry/commands/ls.rb +72 -296
  41. data/lib/pry/commands/ls/constants.rb +47 -0
  42. data/lib/pry/commands/ls/formatter.rb +49 -0
  43. data/lib/pry/commands/ls/globals.rb +48 -0
  44. data/lib/pry/commands/ls/grep.rb +21 -0
  45. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  46. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  47. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  48. data/lib/pry/commands/ls/local_names.rb +35 -0
  49. data/lib/pry/commands/ls/local_vars.rb +39 -0
  50. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  51. data/lib/pry/commands/ls/methods.rb +57 -0
  52. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  53. data/lib/pry/commands/ls/self_methods.rb +32 -0
  54. data/lib/pry/commands/play.rb +44 -10
  55. data/lib/pry/commands/pry_backtrace.rb +1 -2
  56. data/lib/pry/commands/raise_up.rb +2 -2
  57. data/lib/pry/commands/reload_code.rb +16 -19
  58. data/lib/pry/commands/ri.rb +7 -3
  59. data/lib/pry/commands/shell_command.rb +18 -13
  60. data/lib/pry/commands/shell_mode.rb +2 -4
  61. data/lib/pry/commands/show_doc.rb +5 -0
  62. data/lib/pry/commands/show_info.rb +8 -13
  63. data/lib/pry/commands/show_source.rb +15 -3
  64. data/lib/pry/commands/simple_prompt.rb +1 -1
  65. data/lib/pry/commands/toggle_color.rb +8 -4
  66. data/lib/pry/commands/watch_expression.rb +105 -0
  67. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  68. data/lib/pry/commands/whereami.rb +18 -10
  69. data/lib/pry/commands/wtf.rb +3 -3
  70. data/lib/pry/config.rb +20 -254
  71. data/lib/pry/config/behavior.rb +139 -0
  72. data/lib/pry/config/convenience.rb +26 -0
  73. data/lib/pry/config/default.rb +165 -0
  74. data/lib/pry/core_extensions.rb +31 -21
  75. data/lib/pry/editor.rb +107 -103
  76. data/lib/pry/exceptions.rb +77 -0
  77. data/lib/pry/helpers/base_helpers.rb +22 -109
  78. data/lib/pry/helpers/command_helpers.rb +10 -8
  79. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  80. data/lib/pry/helpers/text.rb +4 -5
  81. data/lib/pry/history.rb +46 -45
  82. data/lib/pry/history_array.rb +6 -1
  83. data/lib/pry/hooks.rb +9 -29
  84. data/lib/pry/indent.rb +6 -6
  85. data/lib/pry/input_completer.rb +242 -0
  86. data/lib/pry/input_lock.rb +132 -0
  87. data/lib/pry/inspector.rb +27 -0
  88. data/lib/pry/last_exception.rb +61 -0
  89. data/lib/pry/method.rb +82 -87
  90. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  91. data/lib/pry/module_candidate.rb +4 -14
  92. data/lib/pry/object_path.rb +82 -0
  93. data/lib/pry/output.rb +50 -0
  94. data/lib/pry/pager.rb +193 -48
  95. data/lib/pry/plugins.rb +1 -1
  96. data/lib/pry/prompt.rb +26 -0
  97. data/lib/pry/pry_class.rb +149 -230
  98. data/lib/pry/pry_instance.rb +302 -413
  99. data/lib/pry/rbx_path.rb +1 -1
  100. data/lib/pry/repl.rb +202 -0
  101. data/lib/pry/repl_file_loader.rb +20 -26
  102. data/lib/pry/rubygem.rb +13 -5
  103. data/lib/pry/terminal.rb +2 -1
  104. data/lib/pry/test/helper.rb +26 -41
  105. data/lib/pry/version.rb +1 -1
  106. data/lib/pry/wrapped_module.rb +45 -59
  107. metadata +62 -225
  108. data/.document +0 -2
  109. data/.gitignore +0 -16
  110. data/.travis.yml +0 -25
  111. data/.yardopts +0 -1
  112. data/CHANGELOG +0 -534
  113. data/CONTRIBUTORS +0 -55
  114. data/Gemfile +0 -12
  115. data/Rakefile +0 -140
  116. data/TODO +0 -117
  117. data/lib/pry/completion.rb +0 -321
  118. data/lib/pry/custom_completions.rb +0 -6
  119. data/lib/pry/rbx_method.rb +0 -13
  120. data/man/pry.1 +0 -195
  121. data/man/pry.1.html +0 -204
  122. data/man/pry.1.ronn +0 -141
  123. data/pry.gemspec +0 -29
  124. data/spec/Procfile +0 -3
  125. data/spec/cli_spec.rb +0 -78
  126. data/spec/code_object_spec.rb +0 -277
  127. data/spec/code_spec.rb +0 -219
  128. data/spec/command_helpers_spec.rb +0 -29
  129. data/spec/command_integration_spec.rb +0 -644
  130. data/spec/command_set_spec.rb +0 -627
  131. data/spec/command_spec.rb +0 -821
  132. data/spec/commands/amend_line_spec.rb +0 -247
  133. data/spec/commands/bang_spec.rb +0 -19
  134. data/spec/commands/cat_spec.rb +0 -164
  135. data/spec/commands/cd_spec.rb +0 -250
  136. data/spec/commands/disable_pry_spec.rb +0 -25
  137. data/spec/commands/edit_spec.rb +0 -727
  138. data/spec/commands/exit_all_spec.rb +0 -34
  139. data/spec/commands/exit_program_spec.rb +0 -19
  140. data/spec/commands/exit_spec.rb +0 -34
  141. data/spec/commands/find_method_spec.rb +0 -70
  142. data/spec/commands/gem_list_spec.rb +0 -26
  143. data/spec/commands/gist_spec.rb +0 -79
  144. data/spec/commands/help_spec.rb +0 -56
  145. data/spec/commands/hist_spec.rb +0 -181
  146. data/spec/commands/jump_to_spec.rb +0 -15
  147. data/spec/commands/ls_spec.rb +0 -181
  148. data/spec/commands/play_spec.rb +0 -140
  149. data/spec/commands/raise_up_spec.rb +0 -56
  150. data/spec/commands/save_file_spec.rb +0 -177
  151. data/spec/commands/show_doc_spec.rb +0 -510
  152. data/spec/commands/show_input_spec.rb +0 -17
  153. data/spec/commands/show_source_spec.rb +0 -782
  154. data/spec/commands/whereami_spec.rb +0 -203
  155. data/spec/completion_spec.rb +0 -241
  156. data/spec/control_d_handler_spec.rb +0 -58
  157. data/spec/documentation_helper_spec.rb +0 -73
  158. data/spec/editor_spec.rb +0 -79
  159. data/spec/exception_whitelist_spec.rb +0 -21
  160. data/spec/fixtures/candidate_helper1.rb +0 -11
  161. data/spec/fixtures/candidate_helper2.rb +0 -8
  162. data/spec/fixtures/example.erb +0 -5
  163. data/spec/fixtures/example_nesting.rb +0 -33
  164. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  165. data/spec/fixtures/testrc +0 -2
  166. data/spec/fixtures/testrcbad +0 -2
  167. data/spec/fixtures/whereami_helper.rb +0 -6
  168. data/spec/helper.rb +0 -34
  169. data/spec/helpers/bacon.rb +0 -86
  170. data/spec/helpers/mock_pry.rb +0 -43
  171. data/spec/helpers/table_spec.rb +0 -105
  172. data/spec/history_array_spec.rb +0 -67
  173. data/spec/hooks_spec.rb +0 -522
  174. data/spec/indent_spec.rb +0 -301
  175. data/spec/input_stack_spec.rb +0 -90
  176. data/spec/method_spec.rb +0 -482
  177. data/spec/prompt_spec.rb +0 -60
  178. data/spec/pry_defaults_spec.rb +0 -419
  179. data/spec/pry_history_spec.rb +0 -99
  180. data/spec/pry_output_spec.rb +0 -95
  181. data/spec/pry_spec.rb +0 -515
  182. data/spec/run_command_spec.rb +0 -25
  183. data/spec/sticky_locals_spec.rb +0 -157
  184. data/spec/syntax_checking_spec.rb +0 -81
  185. data/spec/wrapped_module_spec.rb +0 -261
  186. data/wiki/Customizing-pry.md +0 -397
  187. data/wiki/Home.md +0 -4
@@ -1,67 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::HistoryArray do
4
- before do
5
- @array = Pry::HistoryArray.new 10
6
- @populated = @array.dup << 1 << 2 << 3 << 4
7
- end
8
-
9
- it 'should have a maximum size specifed at creation time' do
10
- @array.max_size.should == 10
11
- end
12
-
13
- it 'should be able to be added objects to' do
14
- @populated.size.should == 4
15
- @populated.to_a.should == [1, 2, 3, 4]
16
- end
17
-
18
- it 'should be able to access single elements' do
19
- @populated[2].should == 3
20
- end
21
-
22
- it 'should be able to access negative indices' do
23
- @populated[-1].should == 4
24
- end
25
-
26
- it 'should be able to access ranges' do
27
- @populated[1..2].should == [2, 3]
28
- end
29
-
30
- it 'should be able to access ranges starting from a negative index' do
31
- @populated[-2..3].should == [3, 4]
32
- end
33
-
34
- it 'should be able to access ranges ending at a negative index' do
35
- @populated[2..-1].should == [3, 4]
36
- end
37
-
38
- it 'should be able to access ranges using only negative indices' do
39
- @populated[-2..-1].should == [3, 4]
40
- end
41
-
42
- it 'should be able to use range where end is excluded' do
43
- @populated[-2...-1].should == [3]
44
- end
45
-
46
- it 'should be able to access slices using a size' do
47
- @populated[-3, 2].should == [2, 3]
48
- end
49
-
50
- it 'should remove older entries' do
51
- 11.times { |n| @array << n }
52
-
53
- @array[0].should == nil
54
- @array[1].should == 1
55
- @array[10].should == 10
56
- end
57
-
58
- it 'should not be larger than specified maximum size' do
59
- 12.times { |n| @array << n }
60
- @array.entries.compact.size.should == 10
61
- end
62
-
63
- it 'should pop!' do
64
- @populated.pop!
65
- @populated.to_a.should == [1, 2, 3]
66
- end
67
- end
@@ -1,522 +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
-
320
- options[:hello].should == :baby
321
-
322
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
323
- end
324
-
325
- describe "target" do
326
-
327
- it 'should yield the target, as a binding ' do
328
- b = nil
329
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| b = target }
330
-
331
- redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
332
- Pry.start 5, :hello => :baby
333
- end
334
-
335
- b.is_a?(Binding).should == true
336
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
337
- end
338
-
339
- it 'should yield the target to the hook' do
340
- b = nil
341
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| b = target }
342
-
343
- redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
344
- Pry.start 5, :hello => :baby
345
- end
346
-
347
- b.eval('self').should == 5
348
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
349
- end
350
- end
351
-
352
- it 'should allow overriding of target (and binding_stack)' do
353
- options = nil
354
- o = Object.new
355
- class << o; attr_accessor :value; end
356
-
357
- Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _pry_| _pry_.binding_stack = [Pry.binding_for(o)] }
358
-
359
- redirect_pry_io(InputTester.new("@value = true","exit-all")) do
360
- Pry.start binding, :hello => :baby
361
- end
362
-
363
- o.value.should == true
364
- Pry.config.hooks.delete_hook(:when_started, :test_hook)
365
- end
366
-
367
- end
368
-
369
- describe "after_session hook" do
370
- it 'should always run, even if uncaught exception bubbles out of repl' do
371
- o = OpenStruct.new
372
- o.great_escape = Class.new(StandardError)
373
-
374
- old_ew = Pry.config.exception_whitelist
375
- Pry.config.exception_whitelist << o.great_escape
376
-
377
- array = [1, 2, 3, 4, 5]
378
-
379
- begin
380
- redirect_pry_io(StringIO.new("raise great_escape"), out=StringIO.new) do
381
- Pry.start o, :hooks => Pry::Hooks.new.add_hook(:after_session, :cleanup) { array = nil }
382
- end
383
- rescue => ex
384
- exception = ex
385
- end
386
-
387
- # ensure that an exception really was raised and it broke out
388
- # of the repl
389
- exception.is_a?(o.great_escape).should == true
390
-
391
- # check that after_session hook ran
392
- array.should == nil
393
-
394
- # cleanup after test
395
- Pry.config.exception_whitelist = old_ew
396
- end
397
-
398
- describe "before_eval hook" do
399
- describe "modifying input code" do
400
- it 'should replace input code with code determined by hook' do
401
- hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
402
- redirect_pry_io(InputTester.new(":jemima", "exit-all"), out = StringIO.new) do
403
- Pry.start(self, :hooks => hooks)
404
- end
405
- out.string.should =~ /little_duck/
406
- out.string.should.not =~ /jemima/
407
- end
408
-
409
- it 'should not interfere with command processing when replacing input code' do
410
- commands = Pry::CommandSet.new do
411
- import_from Pry::Commands, "exit-all"
412
-
413
- command "how-do-you-like-your-blue-eyed-boy-now-mister-death" do
414
- output.puts "in hours of bitterness i imagine balls of sapphire, of metal"
415
- end
416
- end
417
-
418
- hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
419
- redirect_pry_io(InputTester.new("how-do-you-like-your-blue-eyed-boy-now-mister-death", "exit-all"), out = StringIO.new) do
420
- Pry.start(self, :hooks => hooks, :commands => commands)
421
- end
422
- out.string.should =~ /in hours of bitterness i imagine balls of sapphire, of metal/
423
- out.string.should.not =~ /little_duck/
424
- end
425
- end
426
-
427
- end
428
-
429
- describe "exceptions" do
430
- before do
431
- Pry.config.hooks.add_hook(:after_eval, :baddums){ raise "Baddums" }
432
- Pry.config.hooks.add_hook(:after_eval, :simbads){ raise "Simbads" }
433
- end
434
-
435
- after do
436
- Pry.config.hooks.delete_hook(:after_eval, :baddums)
437
- Pry.config.hooks.delete_hook(:after_eval, :simbads)
438
- end
439
- it "should not raise exceptions" do
440
- lambda{
441
- mock_pry("1", "2", "3")
442
- }.should.not.raise
443
- end
444
-
445
- it "should print out a notice for each exception raised" do
446
- mock_pry("1").should =~ /after_eval hook failed: RuntimeError: Baddums\n.*after_eval hook failed: RuntimeError: Simbads/m
447
- end
448
- end
449
- end
450
- end
451
-
452
- describe "anonymous hooks" do
453
- it 'should allow adding of hook without a name' do
454
- @hooks.add_hook(:test_hook, nil) {}
455
- @hooks.hook_count(:test_hook).should == 1
456
- end
457
-
458
- it 'should only allow one anonymous hook to exist' do
459
- @hooks.add_hook(:test_hook, nil) { }
460
- @hooks.add_hook(:test_hook, nil) { }
461
- @hooks.hook_count(:test_hook).should == 1
462
- end
463
-
464
- it 'should execute most recently added anonymous hook' do
465
- x = nil
466
- y = nil
467
- @hooks.add_hook(:test_hook, nil) { y = 1 }
468
- @hooks.add_hook(:test_hook, nil) { x = 2 }
469
- @hooks.exec_hook(:test_hook)
470
- y.should == nil
471
- x.should == 2
472
- end
473
- end
474
-
475
- describe "deprecated hash-based API" do
476
- after do
477
- Pry.config.hooks.clear_all if Pry.config.hooks
478
- end
479
-
480
- describe "Pry.config.hooks" do
481
- it 'should allow a hash-assignment' do
482
- Pry.config.hooks = { :before_session => proc { :hello } }
483
- Pry.config.hooks.get_hook(:before_session, nil).call.should == :hello
484
- end
485
-
486
- describe "Pry.config.hooks[]" do
487
- it 'should return the only anonymous hook' do
488
- Pry.config.hooks = { :before_session => proc { :hello } }
489
- Pry.config.hooks[:before_session].call.should == :hello
490
- end
491
-
492
- it 'should add an anonymous hook when using Pry.config.hooks[]=' do
493
- Pry.config.hooks[:before_session] = proc { :bing }
494
- Pry.config.hooks.hook_count(:before_session).should == 1
495
- end
496
-
497
- it 'should add overwrite previous anonymous hooks with new one when calling Pry.config.hooks[]= multiple times' do
498
- x = nil
499
- Pry.config.hooks[:before_session] = proc { x = 1 }
500
- Pry.config.hooks[:before_session] = proc { x = 2 }
501
-
502
- Pry.config.hooks.exec_hook(:before_session)
503
- Pry.config.hooks.hook_count(:before_session).should == 1
504
- x.should == 2
505
- end
506
- end
507
- end
508
-
509
- describe "Pry.start" do
510
- it 'should accept a hash for :hooks parameter' do
511
-
512
- redirect_pry_io(InputTester.new("exit-all"), out=StringIO.new) do
513
- Pry.start binding, :hooks => { :before_session => proc { |output, _, _| output.puts 'hello friend' } }
514
- end
515
-
516
- out.string.should =~ /hello friend/
517
- end
518
-
519
- end
520
- end
521
-
522
- end