pry 0.9.8pre4 → 0.9.8pre5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,380 @@
1
+ require 'helper'
2
+ describe "test Pry defaults" do
3
+
4
+ after do
5
+ Pry.reset_defaults
6
+ Pry.color = false
7
+ end
8
+
9
+ describe "input" do
10
+
11
+ after do
12
+ Pry.reset_defaults
13
+ Pry.color = false
14
+ end
15
+
16
+ it 'should set the input default, and the default should be overridable' do
17
+ Pry.input = InputTester.new("5")
18
+
19
+ str_output = StringIO.new
20
+ Pry.output = str_output
21
+ Pry.new.rep
22
+ str_output.string.should =~ /5/
23
+
24
+ Pry.new(:input => InputTester.new("6")).rep
25
+ str_output.string.should =~ /6/
26
+ end
27
+
28
+ it 'should pass in the prompt if readline arity is 1' do
29
+ Pry.prompt = proc { "A" }
30
+
31
+ arity_one_input = Class.new do
32
+ attr_accessor :prompt
33
+ def readline(prompt)
34
+ @prompt = prompt
35
+ "exit-all"
36
+ end
37
+ end.new
38
+
39
+ Pry.start(self, :input => arity_one_input, :output => Pry::NullOutput)
40
+ arity_one_input.prompt.should == Pry.prompt.call
41
+ end
42
+
43
+ it 'should not pass in the prompt if the arity is 0' do
44
+ Pry.prompt = proc { "A" }
45
+
46
+ arity_zero_input = Class.new do
47
+ def readline
48
+ "exit-all"
49
+ end
50
+ end.new
51
+
52
+ lambda { Pry.start(self, :input => arity_zero_input, :output => Pry::NullOutput) }.should.not.raise Exception
53
+ end
54
+
55
+ it 'should not pass in the prompt if the arity is -1' do
56
+ Pry.prompt = proc { "A" }
57
+
58
+ arity_multi_input = Class.new do
59
+ attr_accessor :prompt
60
+
61
+ def readline(*args)
62
+ @prompt = args.first
63
+ "exit-all"
64
+ end
65
+ end.new
66
+
67
+ Pry.start(self, :input => arity_multi_input, :output => Pry::NullOutput)
68
+ arity_multi_input.prompt.should == nil
69
+ end
70
+
71
+ end
72
+
73
+ it 'should set the output default, and the default should be overridable' do
74
+ Pry.input = InputTester.new("5", "6", "7")
75
+
76
+ str_output = StringIO.new
77
+ Pry.output = str_output
78
+
79
+ Pry.new.rep
80
+ str_output.string.should =~ /5/
81
+
82
+ Pry.new.rep
83
+ str_output.string.should =~ /5\n.*6/
84
+
85
+ str_output2 = StringIO.new
86
+ Pry.new(:output => str_output2).rep
87
+ str_output2.string.should.not =~ /5\n.*6/
88
+ str_output2.string.should =~ /7/
89
+ end
90
+
91
+ it "should set the print default, and the default should be overridable" do
92
+ new_print = proc { |out, value| out.puts value }
93
+ Pry.print = new_print
94
+
95
+ Pry.new.print.should == Pry.print
96
+ str_output = StringIO.new
97
+ Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
98
+ str_output.string.should == "test\n"
99
+
100
+ str_output = StringIO.new
101
+ Pry.new(:input => InputTester.new("\"test\""), :output => str_output,
102
+ :print => proc { |out, value| out.puts value.reverse }).rep
103
+ str_output.string.should == "tset\n"
104
+
105
+ Pry.new.print.should == Pry.print
106
+ str_output = StringIO.new
107
+ Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
108
+ str_output.string.should == "test\n"
109
+ end
110
+
111
+ describe "pry return values" do
112
+ it 'should return nil' do
113
+ Pry.start(self, :input => StringIO.new("exit-all"), :output => Pry::NullOutput).should == nil
114
+ end
115
+
116
+ it 'should return the parameter given to exit-all' do
117
+ Pry.start(self, :input => StringIO.new("exit-all 10"), :output => Pry::NullOutput).should == 10
118
+ end
119
+
120
+ it 'should return the parameter (multi word string) given to exit-all' do
121
+ Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => Pry::NullOutput).should == "john mair"
122
+ end
123
+
124
+ it 'should return the parameter (function call) given to exit-all' do
125
+ Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
126
+ end
127
+
128
+ it 'should return the parameter (self) given to exit-all' do
129
+ Pry.start("carl", :input => StringIO.new("exit-all self"), :output => Pry::NullOutput).should == "carl"
130
+ end
131
+ end
132
+
133
+ describe "prompts" do
134
+ before do
135
+ @empty_input_buffer = ""
136
+ @non_empty_input_buffer = "def hello"
137
+ @context = Pry.binding_for(0)
138
+ end
139
+
140
+ it 'should set the prompt default, and the default should be overridable (single prompt)' do
141
+ new_prompt = proc { "test prompt> " }
142
+ Pry.prompt = new_prompt
143
+
144
+ Pry.new.prompt.should == Pry.prompt
145
+ Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
146
+ Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt> "
147
+
148
+ new_prompt = proc { "A" }
149
+ pry_tester = Pry.new(:prompt => new_prompt)
150
+ pry_tester.prompt.should == new_prompt
151
+ pry_tester.select_prompt(@empty_input_buffer, @context).should == "A"
152
+ pry_tester.select_prompt(@non_empty_input_buffer, @context).should == "A"
153
+
154
+ Pry.new.prompt.should == Pry.prompt
155
+ Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
156
+ Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt> "
157
+ end
158
+
159
+ it 'should set the prompt default, and the default should be overridable (multi prompt)' do
160
+ new_prompt = [proc { "test prompt> " }, proc { "test prompt* " }]
161
+ Pry.prompt = new_prompt
162
+
163
+ Pry.new.prompt.should == Pry.prompt
164
+ Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
165
+ Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt* "
166
+
167
+ new_prompt = [proc { "A" }, proc { "B" }]
168
+ pry_tester = Pry.new(:prompt => new_prompt)
169
+ pry_tester.prompt.should == new_prompt
170
+ pry_tester.select_prompt(@empty_input_buffer, @context).should == "A"
171
+ pry_tester.select_prompt(@non_empty_input_buffer, @context).should == "B"
172
+
173
+ Pry.new.prompt.should == Pry.prompt
174
+ Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
175
+ Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt* "
176
+ end
177
+
178
+ describe 'storing and restoring the prompt' do
179
+ before do
180
+ make = lambda do |name,i|
181
+ prompt = [ proc { "#{i}>" } , proc { "#{i+1}>" } ]
182
+ (class << prompt; self; end).send(:define_method, :inspect) { "<Prompt-#{name}>" }
183
+ prompt
184
+ end
185
+ @a , @b , @c = make[:a,0] , make[:b,1] , make[:c,2]
186
+ @pry = Pry.new :prompt => @a
187
+ end
188
+ it 'should have a prompt stack' do
189
+ @pry.push_prompt @b
190
+ @pry.push_prompt @c
191
+ @pry.prompt.should == @c
192
+ @pry.pop_prompt
193
+ @pry.prompt.should == @b
194
+ @pry.pop_prompt
195
+ @pry.prompt.should == @a
196
+ end
197
+
198
+ it 'should restore overridden prompts when returning from file-mode' do
199
+ pry = Pry.new :input => InputTester.new('shell-mode', 'shell-mode'),
200
+ :prompt => [ proc { 'P>' } ] * 2
201
+ pry.select_prompt(@empty_input_buffer, @context).should == "P>"
202
+ pry.re
203
+ pry.select_prompt(@empty_input_buffer, @context).should =~ /\Apry .* \$ \z/
204
+ pry.re
205
+ pry.select_prompt(@empty_input_buffer, @context).should == "P>"
206
+ end
207
+
208
+ it '#pop_prompt should return the popped prompt' do
209
+ @pry.push_prompt @b
210
+ @pry.push_prompt @c
211
+ @pry.pop_prompt.should == @c
212
+ @pry.pop_prompt.should == @b
213
+ end
214
+
215
+ it 'should not pop the last prompt' do
216
+ @pry.push_prompt @b
217
+ @pry.pop_prompt.should == @b
218
+ @pry.pop_prompt.should == @a
219
+ @pry.pop_prompt.should == @a
220
+ @pry.prompt.should == @a
221
+ end
222
+
223
+ describe '#prompt= should replace the current prompt with the new prompt' do
224
+ it 'when only one prompt on the stack' do
225
+ @pry.prompt = @b
226
+ @pry.prompt.should == @b
227
+ @pry.pop_prompt.should == @b
228
+ @pry.pop_prompt.should == @b
229
+ end
230
+ it 'when several prompts on the stack' do
231
+ @pry.push_prompt @b
232
+ @pry.prompt = @c
233
+ @pry.pop_prompt.should == @c
234
+ @pry.pop_prompt.should == @a
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ describe "view_clip used for displaying an object in a truncated format" do
241
+
242
+ VC_MAX_LENGTH = 60
243
+
244
+ describe "given an object with an #inspect string" do
245
+ it "returns the #<> format of the object (never use inspect)" do
246
+ o = Object.new
247
+ def o.inspect; "a" * VC_MAX_LENGTH; end
248
+
249
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
250
+ end
251
+ end
252
+
253
+ describe "given the 'main' object" do
254
+ it "returns the #to_s of main (special case)" do
255
+ o = TOPLEVEL_BINDING.eval('self')
256
+ Pry.view_clip(o, VC_MAX_LENGTH).should == o.to_s
257
+ end
258
+ end
259
+
260
+ describe "given the a Numeric, String or Symbol object" do
261
+ [1, 2.0, -5, "hello", :test].each do |o|
262
+ it "returns the #inspect of the special-cased immediate object: #{o}" do
263
+ Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
264
+ end
265
+ end
266
+
267
+ # only testing with String here :)
268
+ it "returns #<> format of the special-cased immediate object if #inspect is longer than maximum" do
269
+ o = "o" * (VC_MAX_LENGTH + 1)
270
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<String/
271
+ end
272
+ end
273
+
274
+ describe "given an object with an #inspect string as long as the maximum specified" do
275
+ it "returns the #<> format of the object (never use inspect)" do
276
+ o = Object.new
277
+ def o.inspect; "a" * VC_MAX_LENGTH; end
278
+
279
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
280
+ end
281
+ end
282
+
283
+ describe "given a regular object with an #inspect string longer than the maximum specified" do
284
+
285
+ describe "when the object is a regular one" do
286
+ it "returns a string of the #<class name:object idish> format" do
287
+ o = Object.new
288
+ def o.inspect; "a" * (VC_MAX_LENGTH + 1); end
289
+
290
+ Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
291
+ end
292
+ end
293
+
294
+ describe "when the object is a Class or a Module" do
295
+ describe "without a name (usually a c = Class.new)" do
296
+ it "returns a string of the #<class name:object idish> format" do
297
+ c, m = Class.new, Module.new
298
+
299
+ Pry.view_clip(c, VC_MAX_LENGTH).should =~ /#<Class/
300
+ Pry.view_clip(m, VC_MAX_LENGTH).should =~ /#<Module/
301
+ end
302
+ end
303
+
304
+ describe "with a #name longer than the maximum specified" do
305
+ it "returns a string of the #<class name:object idish> format" do
306
+ c, m = Class.new, Module.new
307
+
308
+
309
+ def c.name; "a" * (VC_MAX_LENGTH + 1); end
310
+ def m.name; "a" * (VC_MAX_LENGTH + 1); end
311
+
312
+ Pry.view_clip(c, VC_MAX_LENGTH).should =~ /#<Class/
313
+ Pry.view_clip(m, VC_MAX_LENGTH).should =~ /#<Module/
314
+ end
315
+ end
316
+
317
+ describe "with a #name shorter than or equal to the maximum specified" do
318
+ it "returns a string of the #<class name:object idish> format" do
319
+ c, m = Class.new, Module.new
320
+
321
+ def c.name; "a" * VC_MAX_LENGTH; end
322
+ def m.name; "a" * VC_MAX_LENGTH; end
323
+
324
+ Pry.view_clip(c, VC_MAX_LENGTH).should == c.name
325
+ Pry.view_clip(m, VC_MAX_LENGTH).should == m.name
326
+ end
327
+ end
328
+
329
+ end
330
+
331
+ end
332
+
333
+ end
334
+
335
+ it 'should set the hooks default, and the default should be overridable' do
336
+ Pry.input = InputTester.new("exit-all")
337
+ Pry.hooks = Pry::Hooks.new.
338
+ add_hook(:before_session, :my_name) { |out,_,_| out.puts "HELLO" }.
339
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "BYE" }
340
+
341
+ str_output = StringIO.new
342
+ Pry.new(:output => str_output).repl
343
+ str_output.string.should =~ /HELLO/
344
+ str_output.string.should =~ /BYE/
345
+
346
+ Pry.input.rewind
347
+
348
+ str_output = StringIO.new
349
+ Pry.new(:output => str_output,
350
+ :hooks => Pry::Hooks.new.
351
+ add_hook( :before_session, :my_name) { |out,_,_| out.puts "MORNING" }.
352
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "EVENING" }
353
+ ).repl
354
+
355
+ str_output.string.should =~ /MORNING/
356
+ str_output.string.should =~ /EVENING/
357
+
358
+ # try below with just defining one hook
359
+ Pry.input.rewind
360
+ str_output = StringIO.new
361
+ Pry.new(:output => str_output,
362
+ :hooks => Pry::Hooks.new.
363
+ add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
364
+ ).repl
365
+
366
+ str_output.string.should =~ /OPEN/
367
+
368
+ Pry.input.rewind
369
+ str_output = StringIO.new
370
+ Pry.new(:output => str_output,
371
+ :hooks => Pry::Hooks.new.
372
+ add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
373
+ ).repl
374
+
375
+ str_output.string.should =~ /CLOSE/
376
+
377
+ Pry.reset_defaults
378
+ Pry.color = false
379
+ end
380
+ end
@@ -55,4 +55,9 @@ describe Pry do
55
55
  pry = Pry.new
56
56
  pry.complete_expression?("puts 1, 2,\n3").should == true
57
57
  end
58
+
59
+ it "should not clobber _ex_ on a SyntaxError in the repl" do
60
+
61
+ mock_pry("raise RuntimeError, 'foo';", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
62
+ end
58
63
  end
metadata CHANGED
@@ -1,95 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pry
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.8pre5
4
5
  prerelease: 5
5
- version: 0.9.8pre4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - John Mair (banisterfiend)
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-01-12 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: coderay
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70205703417720 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
23
21
  version: 1.0.5
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: slop
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70205703417720
25
+ - !ruby/object:Gem::Dependency
26
+ name: slop
27
+ requirement: &70205703416640 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
34
32
  version: 2.4.1
35
33
  - - <
36
- - !ruby/object:Gem::Version
37
- version: "3"
34
+ - !ruby/object:Gem::Version
35
+ version: '3'
38
36
  type: :runtime
39
- version_requirements: *id002
40
- - !ruby/object:Gem::Dependency
41
- name: method_source
42
37
  prerelease: false
43
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ version_requirements: *70205703416640
39
+ - !ruby/object:Gem::Dependency
40
+ name: method_source
41
+ requirement: &70205703415200 !ruby/object:Gem::Requirement
44
42
  none: false
45
- requirements:
43
+ requirements:
46
44
  - - ~>
47
- - !ruby/object:Gem::Version
48
- version: "0.7"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.7'
49
47
  type: :runtime
50
- version_requirements: *id003
51
- - !ruby/object:Gem::Dependency
52
- name: bacon
53
48
  prerelease: false
54
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ version_requirements: *70205703415200
50
+ - !ruby/object:Gem::Dependency
51
+ name: bacon
52
+ requirement: &70205703414620 !ruby/object:Gem::Requirement
55
53
  none: false
56
- requirements:
54
+ requirements:
57
55
  - - ~>
58
- - !ruby/object:Gem::Version
59
- version: "1.1"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.1'
60
58
  type: :development
61
- version_requirements: *id004
62
- - !ruby/object:Gem::Dependency
63
- name: open4
64
59
  prerelease: false
65
- requirement: &id005 !ruby/object:Gem::Requirement
60
+ version_requirements: *70205703414620
61
+ - !ruby/object:Gem::Dependency
62
+ name: open4
63
+ requirement: &70205703413680 !ruby/object:Gem::Requirement
66
64
  none: false
67
- requirements:
65
+ requirements:
68
66
  - - ~>
69
- - !ruby/object:Gem::Version
70
- version: "1.3"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
71
69
  type: :development
72
- version_requirements: *id005
73
- - !ruby/object:Gem::Dependency
74
- name: rake
75
70
  prerelease: false
76
- requirement: &id006 !ruby/object:Gem::Requirement
71
+ version_requirements: *70205703413680
72
+ - !ruby/object:Gem::Dependency
73
+ name: rake
74
+ requirement: &70205703413060 !ruby/object:Gem::Requirement
77
75
  none: false
78
- requirements:
76
+ requirements:
79
77
  - - ~>
80
- - !ruby/object:Gem::Version
81
- version: "0.9"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.9'
82
80
  type: :development
83
- version_requirements: *id006
81
+ prerelease: false
82
+ version_requirements: *70205703413060
84
83
  description: An IRB alternative and runtime developer console
85
84
  email: jrmair@gmail.com
86
- executables:
85
+ executables:
87
86
  - pry
88
87
  extensions: []
89
-
90
88
  extra_rdoc_files: []
91
-
92
- files:
89
+ files:
93
90
  - .document
94
91
  - .gemtest
95
92
  - .gitignore
@@ -159,6 +156,7 @@ files:
159
156
  - test/test_cli.rb
160
157
  - test/test_command.rb
161
158
  - test/test_command_helpers.rb
159
+ - test/test_command_integration.rb
162
160
  - test/test_command_set.rb
163
161
  - test/test_completion.rb
164
162
  - test/test_default_commands.rb
@@ -176,6 +174,7 @@ files:
176
174
  - test/test_input_stack.rb
177
175
  - test/test_method.rb
178
176
  - test/test_pry.rb
177
+ - test/test_pry_defaults.rb
179
178
  - test/test_pry_history.rb
180
179
  - test/test_pry_output.rb
181
180
  - test/test_special_locals.rb
@@ -187,36 +186,34 @@ files:
187
186
  - wiki/Home.md
188
187
  homepage: http://pry.github.com
189
188
  licenses: []
190
-
191
189
  post_install_message:
192
190
  rdoc_options: []
193
-
194
- require_paths:
191
+ require_paths:
195
192
  - lib
196
- required_ruby_version: !ruby/object:Gem::Requirement
193
+ required_ruby_version: !ruby/object:Gem::Requirement
197
194
  none: false
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: "0"
202
- required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ! '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
200
  none: false
204
- requirements:
205
- - - ">"
206
- - !ruby/object:Gem::Version
201
+ requirements:
202
+ - - ! '>'
203
+ - !ruby/object:Gem::Version
207
204
  version: 1.3.1
208
205
  requirements: []
209
-
210
206
  rubyforge_project:
211
- rubygems_version: 1.8.11
207
+ rubygems_version: 1.8.6
212
208
  signing_key:
213
209
  specification_version: 3
214
210
  summary: An IRB alternative and runtime developer console
215
- test_files:
211
+ test_files:
216
212
  - test/helper.rb
217
213
  - test/test_cli.rb
218
214
  - test/test_command.rb
219
215
  - test/test_command_helpers.rb
216
+ - test/test_command_integration.rb
220
217
  - test/test_command_set.rb
221
218
  - test/test_completion.rb
222
219
  - test/test_default_commands.rb
@@ -234,6 +231,7 @@ test_files:
234
231
  - test/test_input_stack.rb
235
232
  - test/test_method.rb
236
233
  - test/test_pry.rb
234
+ - test/test_pry_defaults.rb
237
235
  - test/test_pry_history.rb
238
236
  - test/test_pry_output.rb
239
237
  - test/test_special_locals.rb