pry 0.10.2-i386-mswin32 → 1.0.0.pre1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -0,0 +1,61 @@
1
+ require 'helper'
2
+
3
+ describe "Prompts" do
4
+ describe "one-parameter prompt proc" do
5
+ it 'should get full config object' do
6
+ config = nil
7
+ redirect_pry_io(InputTester.new("exit-all")) do
8
+ Pry.start(self, :prompt => proc { |v| config = v })
9
+ end
10
+ config.is_a?(OpenStruct).should == true
11
+ end
12
+
13
+ it 'should get full config object, when using a proc array' do
14
+ config1 = nil
15
+ redirect_pry_io(InputTester.new("exit-all")) do
16
+ Pry.start(self, :prompt => [proc { |v| config1 = v }, proc { |v| config2 = v }])
17
+ end
18
+ config1.is_a?(OpenStruct).should == true
19
+ end
20
+
21
+ it 'should receive correct data in the config object' do
22
+ config = nil
23
+ redirect_pry_io(InputTester.new("def hello", "exit-all")) do
24
+ Pry.start(self, :prompt => proc { |v| config = v })
25
+ end
26
+
27
+ config.eval_string.should =~ /def hello/
28
+ config.nesting_level.should == 0
29
+ config.expr_number.should == 1
30
+ config.cont.should == true
31
+ config._pry_.is_a?(Pry).should == true
32
+ config.object.should == self
33
+ end
34
+ end
35
+
36
+ describe "BACKWARDS COMPATIBILITY: 3 parameter prompt proc" do
37
+ it 'should get 3 parameters' do
38
+ o = n = p = nil
39
+ redirect_pry_io(InputTester.new("exit-all")) do
40
+ Pry.start(:test, :prompt => proc { |obj, nesting, _pry_|
41
+ o, n, p = obj, nesting, _pry_ })
42
+ end
43
+ o.should == :test
44
+ n.should == 0
45
+ p.is_a?(Pry).should == true
46
+ end
47
+
48
+ it 'should get 3 parameters, when using proc array' do
49
+ o1 = n1 = p1 = nil
50
+ redirect_pry_io(InputTester.new("exit-all")) do
51
+ Pry.start(:test, :prompt => [proc { |obj, nesting, _pry_|
52
+ o1, n1, p1 = obj, nesting, _pry_ },
53
+ proc { |obj, nesting, _pry_|
54
+ o2, n2, p2 = obj, nesting, _pry_ }])
55
+ end
56
+ o1.should == :test
57
+ n1.should == 0
58
+ p1.is_a?(Pry).should == true
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,420 @@
1
+ require 'helper'
2
+
3
+ version = 1
4
+
5
+ describe "test Pry defaults" do
6
+ before do
7
+ @str_output = StringIO.new
8
+ end
9
+
10
+ after do
11
+ Pry.reset_defaults
12
+ Pry.color = false
13
+ end
14
+
15
+ describe "input" do
16
+ after do
17
+ Pry.reset_defaults
18
+ Pry.color = false
19
+ end
20
+
21
+ it 'should set the input default, and the default should be overridable' do
22
+ Pry.input = InputTester.new("5")
23
+ Pry.output = @str_output
24
+ Object.new.pry
25
+ @str_output.string.should =~ /5/
26
+
27
+ Pry.output = @str_output
28
+ Object.new.pry :input => InputTester.new("6")
29
+ @str_output.string.should =~ /6/
30
+ end
31
+
32
+ it 'should pass in the prompt if readline arity is 1' do
33
+ Pry.prompt = proc { "A" }
34
+
35
+ arity_one_input = Class.new do
36
+ attr_accessor :prompt
37
+ def readline(prompt)
38
+ @prompt = prompt
39
+ "exit-all"
40
+ end
41
+ end.new
42
+
43
+ Pry.start(self, :input => arity_one_input, :output => StringIO.new)
44
+ arity_one_input.prompt.should == Pry.prompt.call
45
+ end
46
+
47
+ it 'should not pass in the prompt if the arity is 0' do
48
+ Pry.prompt = proc { "A" }
49
+
50
+ arity_zero_input = Class.new do
51
+ def readline
52
+ "exit-all"
53
+ end
54
+ end.new
55
+
56
+ lambda { Pry.start(self, :input => arity_zero_input, :output => StringIO.new) }.should.not.raise Exception
57
+ end
58
+
59
+ it 'should not pass in the prompt if the arity is -1' do
60
+ Pry.prompt = proc { "A" }
61
+
62
+ arity_multi_input = Class.new do
63
+ attr_accessor :prompt
64
+
65
+ def readline(*args)
66
+ @prompt = args.first
67
+ "exit-all"
68
+ end
69
+ end.new
70
+
71
+ Pry.start(self, :input => arity_multi_input, :output => StringIO.new)
72
+ arity_multi_input.prompt.should == nil
73
+ end
74
+
75
+ end
76
+
77
+ it 'should set the output default, and the default should be overridable' do
78
+ Pry.output = @str_output
79
+
80
+ Pry.input = InputTester.new("5")
81
+ Object.new.pry
82
+ @str_output.string.should =~ /5/
83
+
84
+ Pry.input = InputTester.new("6")
85
+ Object.new.pry
86
+ @str_output.string.should =~ /5\n.*6/
87
+
88
+ Pry.input = InputTester.new("7")
89
+ @str_output = StringIO.new
90
+ Object.new.pry :output => @str_output
91
+ @str_output.string.should.not =~ /5\n.*6/
92
+ @str_output.string.should =~ /7/
93
+ end
94
+
95
+ it "should set the print default, and the default should be overridable" do
96
+ new_print = proc { |out, value| out.puts "=> LOL" }
97
+ Pry.print = new_print
98
+
99
+ Pry.new.print.should == Pry.print
100
+ Object.new.pry :input => InputTester.new("\"test\""), :output => @str_output
101
+ @str_output.string.should == "=> LOL\n"
102
+
103
+ @str_output = StringIO.new
104
+ Object.new.pry :input => InputTester.new("\"test\""), :output => @str_output,
105
+ :print => proc { |out, value| out.puts value.reverse }
106
+ @str_output.string.should == "tset\n"
107
+
108
+ Pry.new.print.should == Pry.print
109
+ @str_output = StringIO.new
110
+ Object.new.pry :input => InputTester.new("\"test\""), :output => @str_output
111
+ @str_output.string.should == "=> LOL\n"
112
+ end
113
+
114
+ describe "pry return values" do
115
+ it 'should return nil' do
116
+ Pry.start(self, :input => StringIO.new("exit-all"), :output => StringIO.new).should == nil
117
+ end
118
+
119
+ it 'should return the parameter given to exit-all' do
120
+ Pry.start(self, :input => StringIO.new("exit-all 10"), :output => StringIO.new).should == 10
121
+ end
122
+
123
+ it 'should return the parameter (multi word string) given to exit-all' do
124
+ Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => StringIO.new).should == "john mair"
125
+ end
126
+
127
+ it 'should return the parameter (function call) given to exit-all' do
128
+ Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => StringIO.new).should == 'cba'
129
+ end
130
+
131
+ it 'should return the parameter (self) given to exit-all' do
132
+ Pry.start("carl", :input => StringIO.new("exit-all self"), :output => StringIO.new).should == "carl"
133
+ end
134
+ end
135
+
136
+ describe "prompts" do
137
+ before do
138
+ Pry.output = StringIO.new
139
+ end
140
+
141
+ def get_prompts(pry)
142
+ a = pry.select_prompt
143
+ pry.eval "["
144
+ b = pry.select_prompt
145
+ pry.eval "]"
146
+ [a, b]
147
+ end
148
+
149
+ it 'should set the prompt default, and the default should be overridable (single prompt)' do
150
+ Pry.prompt = proc { "test prompt> " }
151
+ new_prompt = proc { "A" }
152
+
153
+ pry = Pry.new
154
+ pry.prompt.should == Pry.prompt
155
+ get_prompts(pry).should == ["test prompt> ", "test prompt> "]
156
+
157
+
158
+ pry = Pry.new(:prompt => new_prompt)
159
+ pry.prompt.should == new_prompt
160
+ get_prompts(pry).should == ["A", "A"]
161
+
162
+ pry = Pry.new
163
+ pry.prompt.should == Pry.prompt
164
+ get_prompts(pry).should == ["test prompt> ", "test prompt> "]
165
+ end
166
+
167
+ it 'should set the prompt default, and the default should be overridable (multi prompt)' do
168
+ Pry.prompt = [proc { "test prompt> " }, proc { "test prompt* " }]
169
+ new_prompt = [proc { "A" }, proc { "B" }]
170
+
171
+ pry = Pry.new
172
+ pry.prompt.should == Pry.prompt
173
+ get_prompts(pry).should == ["test prompt> ", "test prompt* "]
174
+
175
+
176
+ pry = Pry.new(:prompt => new_prompt)
177
+ pry.prompt.should == new_prompt
178
+ get_prompts(pry).should == ["A", "B"]
179
+
180
+ pry = Pry.new
181
+ pry.prompt.should == Pry.prompt
182
+ get_prompts(pry).should == ["test prompt> ", "test prompt* "]
183
+ end
184
+
185
+ describe 'storing and restoring the prompt' do
186
+ before do
187
+ make = lambda do |name,i|
188
+ prompt = [ proc { "#{i}>" } , proc { "#{i+1}>" } ]
189
+ (class << prompt; self; end).send(:define_method, :inspect) { "<Prompt-#{name}>" }
190
+ prompt
191
+ end
192
+ @a , @b , @c = make[:a,0] , make[:b,1] , make[:c,2]
193
+ @pry = Pry.new :prompt => @a
194
+ end
195
+ it 'should have a prompt stack' do
196
+ @pry.push_prompt @b
197
+ @pry.push_prompt @c
198
+ @pry.prompt.should == @c
199
+ @pry.pop_prompt
200
+ @pry.prompt.should == @b
201
+ @pry.pop_prompt
202
+ @pry.prompt.should == @a
203
+ end
204
+
205
+ it 'should restore overridden prompts when returning from file-mode' do
206
+ pry = Pry.new(:prompt => [ proc { 'P>' } ] * 2)
207
+ pry.select_prompt.should == "P>"
208
+ pry.process_command('shell-mode')
209
+ pry.select_prompt.should =~ /\Apry .* \$ \z/
210
+ pry.process_command('shell-mode')
211
+ pry.select_prompt.should == "P>"
212
+ end
213
+
214
+ it '#pop_prompt should return the popped prompt' do
215
+ @pry.push_prompt @b
216
+ @pry.push_prompt @c
217
+ @pry.pop_prompt.should == @c
218
+ @pry.pop_prompt.should == @b
219
+ end
220
+
221
+ it 'should not pop the last prompt' do
222
+ @pry.push_prompt @b
223
+ @pry.pop_prompt.should == @b
224
+ @pry.pop_prompt.should == @a
225
+ @pry.pop_prompt.should == @a
226
+ @pry.prompt.should == @a
227
+ end
228
+
229
+ describe '#prompt= should replace the current prompt with the new prompt' do
230
+ it 'when only one prompt on the stack' do
231
+ @pry.prompt = @b
232
+ @pry.prompt.should == @b
233
+ @pry.pop_prompt.should == @b
234
+ @pry.pop_prompt.should == @b
235
+ end
236
+ it 'when several prompts on the stack' do
237
+ @pry.push_prompt @b
238
+ @pry.prompt = @c
239
+ @pry.pop_prompt.should == @c
240
+ @pry.pop_prompt.should == @a
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ describe "view_clip used for displaying an object in a truncated format" do
247
+
248
+ VC_MAX_LENGTH = 60
249
+
250
+ describe "given an object with an #inspect string" do
251
+ it "returns the #<> format of the object (never use inspect)" do
252
+ o = Object.new
253
+ def o.inspect; "a" * VC_MAX_LENGTH; end
254
+
255
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
256
+ end
257
+ end
258
+
259
+ describe "given the 'main' object" do
260
+ it "returns the #to_s of main (special case)" do
261
+ o = TOPLEVEL_BINDING.eval('self')
262
+ Pry.view_clip(o, VC_MAX_LENGTH).should == o.to_s
263
+ end
264
+ end
265
+
266
+ describe "given the a Numeric, String or Symbol object" do
267
+ [1, 2.0, -5, "hello", :test].each do |o|
268
+ it "returns the #inspect of the special-cased immediate object: #{o}" do
269
+ Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
270
+ end
271
+ end
272
+
273
+ # only testing with String here :)
274
+ it "returns #<> format of the special-cased immediate object if #inspect is longer than maximum" do
275
+ o = "o" * (VC_MAX_LENGTH + 1)
276
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<String/
277
+ end
278
+ end
279
+
280
+ describe "given an object with an #inspect string as long as the maximum specified" do
281
+ it "returns the #<> format of the object (never use inspect)" do
282
+ o = Object.new
283
+ def o.inspect; "a" * VC_MAX_LENGTH; end
284
+
285
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
286
+ end
287
+ end
288
+
289
+ describe "given a regular object with an #inspect string longer than the maximum specified" do
290
+
291
+ describe "when the object is a regular one" do
292
+ it "returns a string of the #<class name:object idish> format" do
293
+ o = Object.new
294
+ def o.inspect; "a" * (VC_MAX_LENGTH + 1); end
295
+
296
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
297
+ end
298
+ end
299
+
300
+ describe "when the object is a Class or a Module" do
301
+ describe "without a name (usually a c = Class.new)" do
302
+ it "returns a string of the #<class name:object idish> format" do
303
+ c, m = Class.new, Module.new
304
+
305
+ Pry.view_clip(c, VC_MAX_LENGTH).should =~ /#<Class/
306
+ Pry.view_clip(m, VC_MAX_LENGTH).should =~ /#<Module/
307
+ end
308
+ end
309
+
310
+ describe "with a #name longer than the maximum specified" do
311
+ it "returns a string of the #<class name:object idish> format" do
312
+ c, m = Class.new, Module.new
313
+
314
+
315
+ def c.name; "a" * (VC_MAX_LENGTH + 1); end
316
+ def m.name; "a" * (VC_MAX_LENGTH + 1); end
317
+
318
+ Pry.view_clip(c, VC_MAX_LENGTH).should =~ /#<Class/
319
+ Pry.view_clip(m, VC_MAX_LENGTH).should =~ /#<Module/
320
+ end
321
+ end
322
+
323
+ describe "with a #name shorter than or equal to the maximum specified" do
324
+ it "returns a string of the #<class name:object idish> format" do
325
+ c, m = Class.new, Module.new
326
+
327
+ def c.name; "a" * VC_MAX_LENGTH; end
328
+ def m.name; "a" * VC_MAX_LENGTH; end
329
+
330
+ Pry.view_clip(c, VC_MAX_LENGTH).should == c.name
331
+ Pry.view_clip(m, VC_MAX_LENGTH).should == m.name
332
+ end
333
+ end
334
+
335
+ end
336
+
337
+ end
338
+
339
+ end
340
+
341
+ describe 'quiet' do
342
+ it 'should show whereami by default' do
343
+ Pry.start(binding, :input => InputTester.new("1", "exit-all"),
344
+ :output => @str_output,
345
+ :hooks => Pry::DEFAULT_HOOKS)
346
+
347
+ @str_output.string.should =~ /[w]hereami by default/
348
+ end
349
+
350
+ it 'should hide whereami if quiet is set' do
351
+ Pry.new(:input => InputTester.new("exit-all"),
352
+ :output => @str_output,
353
+ :quiet => true,
354
+ :hooks => Pry::DEFAULT_HOOKS)
355
+
356
+ @str_output.string.should == ""
357
+ end
358
+ end
359
+
360
+ describe 'toplevel_binding' do
361
+ it 'should be devoid of local variables' do
362
+ pry_eval(Pry.toplevel_binding, "ls -l").should.not =~ /version/
363
+ end
364
+
365
+ it 'should have self the same as TOPLEVEL_BINDING' do
366
+ Pry.toplevel_binding.eval('self').should.equal? TOPLEVEL_BINDING.eval('self')
367
+ end
368
+
369
+ # https://github.com/rubinius/rubinius/issues/1779
370
+ unless Pry::Helpers::BaseHelpers.rbx?
371
+ it 'should define private methods on Object' do
372
+ TOPLEVEL_BINDING.eval 'def gooey_fooey; end'
373
+ method(:gooey_fooey).owner.should == Object
374
+ Pry::Method(method(:gooey_fooey)).visibility.should == :private
375
+ end
376
+ end
377
+ end
378
+
379
+ it 'should set the hooks default, and the default should be overridable' do
380
+ Pry.input = InputTester.new("exit-all")
381
+ Pry.hooks = Pry::Hooks.new.
382
+ add_hook(:before_session, :my_name) { |out,_,_| out.puts "HELLO" }.
383
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "BYE" }
384
+
385
+ Object.new.pry :output => @str_output
386
+ @str_output.string.should =~ /HELLO/
387
+ @str_output.string.should =~ /BYE/
388
+
389
+ Pry.input.rewind
390
+
391
+ @str_output = StringIO.new
392
+ Object.new.pry :output => @str_output,
393
+ :hooks => Pry::Hooks.new.
394
+ add_hook( :before_session, :my_name) { |out,_,_| out.puts "MORNING" }.
395
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "EVENING" }
396
+
397
+ @str_output.string.should =~ /MORNING/
398
+ @str_output.string.should =~ /EVENING/
399
+
400
+ # try below with just defining one hook
401
+ Pry.input.rewind
402
+ @str_output = StringIO.new
403
+ Object.new.pry :output => @str_output,
404
+ :hooks => Pry::Hooks.new.
405
+ add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
406
+
407
+ @str_output.string.should =~ /OPEN/
408
+
409
+ Pry.input.rewind
410
+ @str_output = StringIO.new
411
+ Object.new.pry :output => @str_output,
412
+ :hooks => Pry::Hooks.new.
413
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
414
+
415
+ @str_output.string.should =~ /CLOSE/
416
+
417
+ Pry.reset_defaults
418
+ Pry.color = false
419
+ end
420
+ end