pry 0.9.8pre4-i386-mingw32 → 0.9.8pre5-i386-mingw32

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,106 +1,103 @@
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: i386-mingw32
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: &70205700417980 !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: *70205700417980
25
+ - !ruby/object:Gem::Dependency
26
+ name: slop
27
+ requirement: &70205700415660 !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: *70205700415660
39
+ - !ruby/object:Gem::Dependency
40
+ name: method_source
41
+ requirement: &70205700411540 !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: *70205700411540
50
+ - !ruby/object:Gem::Dependency
51
+ name: bacon
52
+ requirement: &70205700409320 !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: *70205700409320
61
+ - !ruby/object:Gem::Dependency
62
+ name: open4
63
+ requirement: &70205700406140 !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: *70205700406140
72
+ - !ruby/object:Gem::Dependency
73
+ name: rake
74
+ requirement: &70205700403500 !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
84
- - !ruby/object:Gem::Dependency
85
- name: win32console
86
81
  prerelease: false
87
- requirement: &id007 !ruby/object:Gem::Requirement
82
+ version_requirements: *70205700403500
83
+ - !ruby/object:Gem::Dependency
84
+ name: win32console
85
+ requirement: &70205700400720 !ruby/object:Gem::Requirement
88
86
  none: false
89
- requirements:
87
+ requirements:
90
88
  - - ~>
91
- - !ruby/object:Gem::Version
92
- version: "1.3"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.3'
93
91
  type: :runtime
94
- version_requirements: *id007
92
+ prerelease: false
93
+ version_requirements: *70205700400720
95
94
  description: An IRB alternative and runtime developer console
96
95
  email: jrmair@gmail.com
97
- executables:
96
+ executables:
98
97
  - pry
99
98
  extensions: []
100
-
101
99
  extra_rdoc_files: []
102
-
103
- files:
100
+ files:
104
101
  - .document
105
102
  - .gemtest
106
103
  - .gitignore
@@ -170,6 +167,7 @@ files:
170
167
  - test/test_cli.rb
171
168
  - test/test_command.rb
172
169
  - test/test_command_helpers.rb
170
+ - test/test_command_integration.rb
173
171
  - test/test_command_set.rb
174
172
  - test/test_completion.rb
175
173
  - test/test_default_commands.rb
@@ -187,6 +185,7 @@ files:
187
185
  - test/test_input_stack.rb
188
186
  - test/test_method.rb
189
187
  - test/test_pry.rb
188
+ - test/test_pry_defaults.rb
190
189
  - test/test_pry_history.rb
191
190
  - test/test_pry_output.rb
192
191
  - test/test_special_locals.rb
@@ -198,36 +197,34 @@ files:
198
197
  - wiki/Home.md
199
198
  homepage: http://pry.github.com
200
199
  licenses: []
201
-
202
200
  post_install_message:
203
201
  rdoc_options: []
204
-
205
- require_paths:
202
+ require_paths:
206
203
  - lib
207
- required_ruby_version: !ruby/object:Gem::Requirement
204
+ required_ruby_version: !ruby/object:Gem::Requirement
208
205
  none: false
209
- requirements:
210
- - - ">="
211
- - !ruby/object:Gem::Version
212
- version: "0"
213
- required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
211
  none: false
215
- requirements:
216
- - - ">"
217
- - !ruby/object:Gem::Version
212
+ requirements:
213
+ - - ! '>'
214
+ - !ruby/object:Gem::Version
218
215
  version: 1.3.1
219
216
  requirements: []
220
-
221
217
  rubyforge_project:
222
- rubygems_version: 1.8.11
218
+ rubygems_version: 1.8.6
223
219
  signing_key:
224
220
  specification_version: 3
225
221
  summary: An IRB alternative and runtime developer console
226
- test_files:
222
+ test_files:
227
223
  - test/helper.rb
228
224
  - test/test_cli.rb
229
225
  - test/test_command.rb
230
226
  - test/test_command_helpers.rb
227
+ - test/test_command_integration.rb
231
228
  - test/test_command_set.rb
232
229
  - test/test_completion.rb
233
230
  - test/test_default_commands.rb
@@ -245,6 +242,7 @@ test_files:
245
242
  - test/test_input_stack.rb
246
243
  - test/test_method.rb
247
244
  - test/test_pry.rb
245
+ - test/test_pry_defaults.rb
248
246
  - test/test_pry_history.rb
249
247
  - test/test_pry_output.rb
250
248
  - test/test_special_locals.rb