pry 0.9.0pre3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,11 +13,118 @@ describe "Pry::DefaultCommands::Input" do
13
13
 
14
14
  it 'should correctly amend the specified line of input when line number given ' do
15
15
  str_output = StringIO.new
16
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line-0 def goodbye", "show-input", "exit-all"), str_output) do
16
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 1 def goodbye", "show-input", "exit-all"), str_output) do
17
17
  pry
18
18
  end
19
19
  str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
20
20
  end
21
+
22
+ it 'should correctly amend the specified line of input when line number given, 0 should behave as 1 ' do
23
+ str_output = StringIO.new
24
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 0 def goodbye", "show-input", "exit-all"), str_output) do
25
+ pry
26
+ end
27
+ str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
28
+ end
29
+
30
+ it 'should correctly amend the specified line of input when line number given (negative number)' do
31
+ str_output = StringIO.new
32
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -1 puts :bink", "show-input", "exit-all"), str_output) do
33
+ pry
34
+ end
35
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts :bink/
36
+
37
+ str_output = StringIO.new
38
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -2 puts :bink", "show-input", "exit-all"), str_output) do
39
+ pry
40
+ end
41
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :bang/
42
+ end
43
+
44
+ it 'should correctly amend the specified range of lines of input when range of negative numbers given (negative number)' do
45
+ str_output = StringIO.new
46
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boat", "amend-line -3..-2 puts :bink", "show-input", "exit-all"), str_output) do
47
+ pry
48
+ end
49
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :boat/
50
+ end
51
+
52
+ it 'should correctly amend the specified line with string interpolated text' do
53
+ str_output = StringIO.new
54
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", 'amend-line puts "#{goodbye}"', "show-input", "exit-all"), str_output) do
55
+ pry
56
+ end
57
+
58
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts \"\#{goodbye}\"/
59
+ end
60
+
61
+ it 'should display error if nothing to amend' do
62
+ str_output = StringIO.new
63
+ redirect_pry_io(InputTester.new("amend-line", "exit-all"), str_output) do
64
+ pry
65
+ end
66
+ str_output.string.should =~ /No input to amend/
67
+ end
68
+
69
+
70
+ it 'should correctly amend the specified range of lines' do
71
+ str_output = StringIO.new
72
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :heart", "amend-line 2..3 puts :bong", "show-input", "exit-all"), str_output) do
73
+ pry
74
+ end
75
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
76
+ end
77
+
78
+ it 'should correctly delete a specific line using the ! for content' do
79
+ str_output = StringIO.new
80
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 3 !", "show-input", "exit-all"), str_output) do
81
+ pry
82
+ end
83
+
84
+ str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :boast\n\d+: puts :heart/
85
+ end
86
+
87
+ it 'should correctly delete a range of lines using the ! for content' do
88
+ str_output = StringIO.new
89
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 2..4 !", "show-input", "exit-all"), str_output) do
90
+ pry
91
+ end
92
+
93
+ str_output.string.should =~ /\d+: def hello\n\d+: puts :heart\n\Z/
94
+ end
95
+
96
+ it 'should correctly delete the previous line using the ! for content' do
97
+ str_output = StringIO.new
98
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line !", "show-input", "exit-all"), str_output) do
99
+ pry
100
+ end
101
+
102
+ str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :bang\n\d+: puts :boast\n\Z/
103
+ end
104
+
105
+ it 'should correctly amend the specified range of lines, using negative numbers in range' do
106
+ str_output = StringIO.new
107
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line-2..-2 puts :bong", "show-input", "exit-all"), str_output) do
108
+ pry
109
+ end
110
+ str_output.string.should =~ /\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
111
+ end
112
+
113
+ it 'should correctly insert a new line of input before a specified line using the > syntax' do
114
+ str_output = StringIO.new
115
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2 >puts :inserted", "show-input", "exit-all"), str_output) do
116
+ pry
117
+ end
118
+ str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
119
+ end
120
+
121
+ it 'should correctly insert a new line of input before a specified line using the > syntax (should ignore second value of range)' do
122
+ str_output = StringIO.new
123
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2..21 >puts :inserted", "show-input", "exit-all"), str_output) do
124
+ pry
125
+ end
126
+ str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
127
+ end
21
128
  end
22
129
 
23
130
  describe "show-input" do
@@ -42,6 +149,53 @@ describe "Pry::DefaultCommands::Input" do
42
149
  end
43
150
  end
44
151
 
152
+ describe "play" do
153
+ it 'should play a string of code (with no args)' do
154
+ redirect_pry_io(InputTester.new("play :test_string", "exit-all"), str_output = StringIO.new) do
155
+ pry
156
+ end
157
+ str_output.string.should =~ /:test_string/
158
+ end
159
+
160
+ it 'should play an interpolated string of code (with no args)' do
161
+ $obj = ":test_string_interpolated"
162
+ redirect_pry_io(InputTester.new('play #{$obj}', "exit-all"), str_output = StringIO.new) do
163
+ pry
164
+ end
165
+ str_output.string.should =~ /:test_string_interpolated/
166
+ end
167
+
168
+ it 'should play a method with the -m switch (a single line)' do
169
+ $o = Object.new
170
+ def $o.test_method
171
+ :test_method_content
172
+ end
173
+
174
+ redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2', "exit-all"), str_output = StringIO.new) do
175
+ pry
176
+ end
177
+
178
+ str_output.string.should =~ /:test_method_content/
179
+ $o = nil
180
+ end
181
+
182
+ it 'should play a method with the -m switch (multiple line)' do
183
+ $o = Object.new
184
+ def $o.test_method
185
+ 1 + 102
186
+ 5 * 6
187
+ end
188
+
189
+ redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2..3', "exit-all"), str_output = StringIO.new) do
190
+ pry
191
+ end
192
+
193
+ str_output.string.should =~ /103\n.*30/
194
+ $o = nil
195
+ end
196
+
197
+ end
198
+
45
199
  describe "hist" do
46
200
  push_first_hist_line = lambda do |hist, line|
47
201
  hist.push line
@@ -94,13 +248,29 @@ describe "Pry::DefaultCommands::Input" do
94
248
  @hist.push "pepper"
95
249
  @hist.push "orange"
96
250
  @hist.push "grape"
251
+ @hist.push "def blah 1"
252
+ @hist.push "def boink 2"
253
+ @hist.push "place holder"
97
254
 
98
255
  str_output = StringIO.new
99
256
  redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do
100
257
  pry
101
258
  end
102
-
103
259
  str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
260
+
261
+ # test more than one word in a regex match (def blah)
262
+ str_output = StringIO.new
263
+ redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all"), str_output) do
264
+ pry
265
+ end
266
+ str_output.string.should =~ /def blah 1/
267
+
268
+ # test more than one word with leading white space in a regex match (def boink)
269
+ str_output = StringIO.new
270
+ redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all"), str_output) do
271
+ pry
272
+ end
273
+ str_output.string.should =~ /def boink 2/
104
274
  end
105
275
 
106
276
  it 'should return last N lines in history with --tail switch' do
@@ -20,6 +20,15 @@ describe "Pry::DefaultCommands::Introspection" do
20
20
  str_output.string.should =~ /\d+: def sample/
21
21
  end
22
22
 
23
+ it 'should output a method\'s source with line numbers starting at 1' do
24
+ str_output = StringIO.new
25
+ redirect_pry_io(InputTester.new("show-method -b sample_method", "exit-all"), str_output) do
26
+ pry
27
+ end
28
+
29
+ str_output.string.should =~ /1: def sample/
30
+ end
31
+
23
32
  it 'should output a method\'s source if inside method without needing to use method name' do
24
33
  $str_output = StringIO.new
25
34
 
@@ -40,6 +40,17 @@ describe Pry do
40
40
  @excep.is_a?(NameError).should == true
41
41
  end
42
42
 
43
+ if defined?(BasicObject)
44
+ it 'should be able to operate inside the BasicObject class' do
45
+ $obj = nil
46
+ redirect_pry_io(InputTester.new(":foo", "$obj = _", "exit-all"), StringIO.new) do
47
+ BasicObject.pry
48
+ end
49
+ $obj.should == :foo
50
+ $obj = nil
51
+ end
52
+ end
53
+
43
54
  it 'should set an ivar on an object' do
44
55
  input_string = "@x = 10"
45
56
  input = InputTester.new(input_string)
@@ -488,6 +499,21 @@ describe Pry do
488
499
  $test_interpolation = nil
489
500
  end
490
501
 
502
+ it 'should NOT try to interpolate pure ruby code (no commands) ' do
503
+ str_output = StringIO.new
504
+ Pry.new(:input => StringIO.new('puts \'#{aggy}\''), :output => str_output).rep
505
+ str_output.string.should.not =~ /NameError/
506
+
507
+ Pry.new(:input => StringIO.new('puts #{aggy}'), :output => str_output).rep
508
+ str_output.string.should.not =~ /NameError/
509
+
510
+ $test_interpolation = "blah"
511
+ Pry.new(:input => StringIO.new('puts \'#{$test_interpolation}\''), :output => str_output).rep
512
+
513
+ str_output.string.should.not =~ /blah/
514
+ $test_interpolation = nil
515
+ end
516
+
491
517
  it 'should create a command with a space in its name' do
492
518
  set = Pry::CommandSet.new do
493
519
  command "hello baby", "" do
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 5
5
- version: 0.9.0pre3
4
+ prerelease:
5
+ version: 0.9.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Mair (banisterfiend)
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-09 00:00:00 Z
13
+ date: 2011-06-17 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_parser
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.6.0
45
+ version: 1.9.0
46
46
  type: :runtime
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 0.4.0
56
+ version: 0.6.0
57
57
  type: :runtime
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,7 @@ files:
137
137
  - lib/pry/pry_class.rb
138
138
  - lib/pry/pry_instance.rb
139
139
  - lib/pry/version.rb
140
+ - pry.gemspec
140
141
  - test/helper.rb
141
142
  - test/test_command_helpers.rb
142
143
  - test/test_command_processor.rb
@@ -169,9 +170,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
170
  required_rubygems_version: !ruby/object:Gem::Requirement
170
171
  none: false
171
172
  requirements:
172
- - - ">"
173
+ - - ">="
173
174
  - !ruby/object:Gem::Version
174
- version: 1.3.1
175
+ version: "0"
175
176
  requirements: []
176
177
 
177
178
  rubyforge_project: