pry 0.9.4pre1-i386-mswin32 → 0.9.4pre2-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +23 -0
- data/CONTRIBUTORS +13 -11
- data/README.markdown +2 -0
- data/Rakefile +16 -2
- data/TODO +8 -0
- data/lib/pry.rb +58 -9
- data/lib/pry/command_context.rb +11 -0
- data/lib/pry/command_processor.rb +43 -6
- data/lib/pry/command_set.rb +14 -4
- data/lib/pry/completion.rb +5 -5
- data/lib/pry/config.rb +6 -2
- data/lib/pry/default_commands/context.rb +83 -35
- data/lib/pry/default_commands/documentation.rb +37 -31
- data/lib/pry/default_commands/easter_eggs.rb +5 -0
- data/lib/pry/default_commands/input.rb +13 -10
- data/lib/pry/default_commands/introspection.rb +54 -40
- data/lib/pry/default_commands/shell.rb +9 -5
- data/lib/pry/helpers/base_helpers.rb +16 -5
- data/lib/pry/helpers/command_helpers.rb +41 -17
- data/lib/pry/helpers/text.rb +2 -1
- data/lib/pry/history.rb +61 -0
- data/lib/pry/plugins.rb +19 -8
- data/lib/pry/pry_class.rb +25 -62
- data/lib/pry/pry_instance.rb +105 -120
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +15 -14
- data/test/helper.rb +31 -0
- data/test/test_command_set.rb +7 -2
- data/test/test_completion.rb +7 -3
- data/test/test_default_commands/test_context.rb +185 -1
- data/test/test_default_commands/test_documentation.rb +10 -0
- data/test/test_default_commands/test_input.rb +16 -11
- data/test/test_default_commands/test_introspection.rb +10 -0
- data/test/test_default_commands/test_shell.rb +18 -0
- data/test/test_pry.rb +189 -40
- data/test/test_pry_history.rb +13 -13
- data/test/test_pry_output.rb +44 -0
- data/test/test_special_locals.rb +35 -0
- metadata +182 -173
data/test/test_pry.rb
CHANGED
@@ -7,7 +7,7 @@ puts "--"
|
|
7
7
|
|
8
8
|
describe Pry do
|
9
9
|
|
10
|
-
if RUBY_PLATFORM !~ /mingw/ && RUBY_PLATFORM !~ /mswin/
|
10
|
+
if RUBY_PLATFORM !~ /mingw/ && RUBY_PLATFORM !~ /mswin/ && RUBY_PLATFORM != 'java'
|
11
11
|
describe 'warning emissions' do
|
12
12
|
it 'should emit no warnings' do
|
13
13
|
Open4.popen4 'ruby -I lib -rubygems -r"pry" -W -e "exit"' do |pid, stdin, stdout, stderr|
|
@@ -33,7 +33,6 @@ describe Pry do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
describe "Pry.binding_for" do
|
38
37
|
|
39
38
|
# regression test for burg's bug (see git history)
|
@@ -93,6 +92,18 @@ describe Pry do
|
|
93
92
|
o.instance_variable_get(:@x).should == 10
|
94
93
|
end
|
95
94
|
|
95
|
+
it 'should not output anything for no input' do
|
96
|
+
outp = StringIO.new
|
97
|
+
|
98
|
+
# note i could not use mock_pry() for this test for some
|
99
|
+
# reason, as i'd always get "\n" as output instead of ""
|
100
|
+
redirect_pry_io(StringIO.new(""), outp) do
|
101
|
+
Pry.new.rep(self)
|
102
|
+
end
|
103
|
+
|
104
|
+
outp.string.empty?.should == true
|
105
|
+
end
|
106
|
+
|
96
107
|
it 'should make self evaluate to the receiver of the rep session' do
|
97
108
|
o = :john
|
98
109
|
str_output = StringIO.new
|
@@ -170,12 +181,18 @@ describe Pry do
|
|
170
181
|
pry_tester.rep(o)
|
171
182
|
was_called.should == true
|
172
183
|
end
|
184
|
+
|
185
|
+
it 'should not try to catch intended exceptions' do
|
186
|
+
lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
|
187
|
+
# SIGTERM
|
188
|
+
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
189
|
+
end
|
173
190
|
end
|
174
191
|
|
175
192
|
describe "repl" do
|
176
193
|
describe "basic functionality" do
|
177
194
|
it 'should set an ivar on an object and exit the repl' do
|
178
|
-
input_strings = ["@x = 10", "exit"]
|
195
|
+
input_strings = ["@x = 10", "exit-all"]
|
179
196
|
input = InputTester.new(*input_strings)
|
180
197
|
|
181
198
|
o = Object.new
|
@@ -198,7 +215,7 @@ describe Pry do
|
|
198
215
|
|
199
216
|
it 'sets out to an array with the result' do
|
200
217
|
res = {}
|
201
|
-
input = InputTester.new *[":foo", "42", "self[:res] =
|
218
|
+
input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
|
202
219
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
203
220
|
pry.repl(res)
|
204
221
|
|
@@ -206,9 +223,9 @@ describe Pry do
|
|
206
223
|
res[:res][1..2].should == [:foo, 42]
|
207
224
|
end
|
208
225
|
|
209
|
-
it 'sets
|
226
|
+
it 'sets _in_ to an array with the entered lines' do
|
210
227
|
res = {}
|
211
|
-
input = InputTester.new *[":foo", "42", "self[:res] =
|
228
|
+
input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
|
212
229
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
213
230
|
pry.repl(res)
|
214
231
|
|
@@ -216,9 +233,9 @@ describe Pry do
|
|
216
233
|
res[:res][1..2].should == [":foo\n", "42\n"]
|
217
234
|
end
|
218
235
|
|
219
|
-
it 'uses 100 as the size of
|
236
|
+
it 'uses 100 as the size of _in_ and _out_' do
|
220
237
|
res = []
|
221
|
-
input = InputTester.new *["self <<
|
238
|
+
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
222
239
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
223
240
|
pry.repl(res)
|
224
241
|
|
@@ -227,7 +244,7 @@ describe Pry do
|
|
227
244
|
|
228
245
|
it 'can change the size of the history arrays' do
|
229
246
|
res = []
|
230
|
-
input = InputTester.new *["self <<
|
247
|
+
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
231
248
|
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
232
249
|
:memory_size => 1000)
|
233
250
|
pry.repl(res)
|
@@ -237,7 +254,7 @@ describe Pry do
|
|
237
254
|
|
238
255
|
it 'store exceptions' do
|
239
256
|
res = []
|
240
|
-
input = InputTester.new *["foo!","self <<
|
257
|
+
input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
|
241
258
|
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
242
259
|
:memory_size => 1000)
|
243
260
|
pry.repl(res)
|
@@ -262,10 +279,10 @@ describe Pry do
|
|
262
279
|
Pry.config.should_load_rc = true
|
263
280
|
Pry::RC_FILES << File.expand_path("../testrc", __FILE__)
|
264
281
|
|
265
|
-
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
282
|
+
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
266
283
|
TEST_RC.should == [0]
|
267
284
|
|
268
|
-
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
285
|
+
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
269
286
|
TEST_RC.should == [0]
|
270
287
|
|
271
288
|
Object.remove_const(:TEST_RC)
|
@@ -273,13 +290,13 @@ describe Pry do
|
|
273
290
|
|
274
291
|
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
|
275
292
|
Pry.config.should_load_rc = false
|
276
|
-
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
293
|
+
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
277
294
|
Object.const_defined?(:TEST_RC).should == false
|
278
295
|
end
|
279
296
|
|
280
297
|
it "should not load the rc file if #repl method invoked" do
|
281
298
|
Pry.config.should_load_rc = true
|
282
|
-
Pry.new(:input => StringIO.new("exit\n"), :output => Pry::NullOutput).repl(self)
|
299
|
+
Pry.new(:input => StringIO.new("exit-all\n"), :output => Pry::NullOutput).repl(self)
|
283
300
|
Object.const_defined?(:TEST_RC).should == false
|
284
301
|
Pry.config.should_load_rc = false
|
285
302
|
end
|
@@ -292,7 +309,7 @@ describe Pry do
|
|
292
309
|
end
|
293
310
|
|
294
311
|
it 'should nest properly' do
|
295
|
-
Pry.input = InputTester.new("
|
312
|
+
Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
|
296
313
|
|
297
314
|
str_output = StringIO.new
|
298
315
|
Pry.output = str_output
|
@@ -343,7 +360,7 @@ describe Pry do
|
|
343
360
|
it 'should run a command with no parameter' do
|
344
361
|
pry_tester = Pry.new
|
345
362
|
pry_tester.commands = CommandTester
|
346
|
-
pry_tester.input = InputTester.new("command1", "
|
363
|
+
pry_tester.input = InputTester.new("command1", "exit-all")
|
347
364
|
pry_tester.commands = CommandTester
|
348
365
|
|
349
366
|
str_output = StringIO.new
|
@@ -357,7 +374,7 @@ describe Pry do
|
|
357
374
|
it 'should run a command with one parameter' do
|
358
375
|
pry_tester = Pry.new
|
359
376
|
pry_tester.commands = CommandTester
|
360
|
-
pry_tester.input = InputTester.new("command2 horsey", "
|
377
|
+
pry_tester.input = InputTester.new("command2 horsey", "exit-all")
|
361
378
|
pry_tester.commands = CommandTester
|
362
379
|
|
363
380
|
str_output = StringIO.new
|
@@ -377,7 +394,7 @@ describe Pry do
|
|
377
394
|
end
|
378
395
|
|
379
396
|
it "should start a pry session on the receiver (first form)" do
|
380
|
-
Pry.input = InputTester.new("self", "exit")
|
397
|
+
Pry.input = InputTester.new("self", "exit-all")
|
381
398
|
|
382
399
|
str_output = StringIO.new
|
383
400
|
Pry.output = str_output
|
@@ -388,7 +405,7 @@ describe Pry do
|
|
388
405
|
end
|
389
406
|
|
390
407
|
it "should start a pry session on the receiver (second form)" do
|
391
|
-
Pry.input = InputTester.new("self", "exit")
|
408
|
+
Pry.input = InputTester.new("self", "exit-all")
|
392
409
|
|
393
410
|
str_output = StringIO.new
|
394
411
|
Pry.output = str_output
|
@@ -446,7 +463,7 @@ describe Pry do
|
|
446
463
|
attr_accessor :prompt
|
447
464
|
def readline(prompt)
|
448
465
|
@prompt = prompt
|
449
|
-
"exit"
|
466
|
+
"exit-all"
|
450
467
|
end
|
451
468
|
end.new
|
452
469
|
|
@@ -459,7 +476,7 @@ describe Pry do
|
|
459
476
|
|
460
477
|
arity_zero_input = Class.new do
|
461
478
|
def readline
|
462
|
-
"exit"
|
479
|
+
"exit-all"
|
463
480
|
end
|
464
481
|
end.new
|
465
482
|
|
@@ -474,7 +491,7 @@ describe Pry do
|
|
474
491
|
|
475
492
|
def readline(*args)
|
476
493
|
@prompt = args.first
|
477
|
-
"exit"
|
494
|
+
"exit-all"
|
478
495
|
end
|
479
496
|
end.new
|
480
497
|
|
@@ -672,15 +689,13 @@ describe Pry do
|
|
672
689
|
end
|
673
690
|
|
674
691
|
it 'should create a command in a nested context and that command should be accessible from the parent' do
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
Pry.
|
679
|
-
obj = Object.new
|
680
|
-
Pry.new(:output => str_output).repl(obj)
|
681
|
-
Pry.input = Readline
|
682
|
-
str_output.string.should =~ /@x/
|
692
|
+
str_output = StringIO.new
|
693
|
+
x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
|
694
|
+
redirect_pry_io(StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"), str_output) do
|
695
|
+
Pry.new.repl(0)
|
683
696
|
end
|
697
|
+
|
698
|
+
str_output.string.should =~ /@x/
|
684
699
|
end
|
685
700
|
|
686
701
|
it 'should define a command that keeps its return value' do
|
@@ -707,6 +722,66 @@ describe Pry do
|
|
707
722
|
str_output.string !~ /=>/
|
708
723
|
end
|
709
724
|
|
725
|
+
it 'should define a command that keeps its return value even when nil' do
|
726
|
+
klass = Pry::CommandSet.new do
|
727
|
+
command "hello", "", :keep_retval => true do
|
728
|
+
nil
|
729
|
+
end
|
730
|
+
end
|
731
|
+
str_output = StringIO.new
|
732
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
733
|
+
str_output.string.should =~ /nil/
|
734
|
+
str_output.string.should =~ /=>/
|
735
|
+
end
|
736
|
+
|
737
|
+
it 'should define a command that keeps its return value but does not return when value is void' do
|
738
|
+
klass = Pry::CommandSet.new do
|
739
|
+
command "hello", "", :keep_retval => true do
|
740
|
+
void
|
741
|
+
end
|
742
|
+
end
|
743
|
+
str_output = StringIO.new
|
744
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
745
|
+
str_output.string.empty?.should == true
|
746
|
+
end
|
747
|
+
|
748
|
+
it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
|
749
|
+
klass = Pry::CommandSet.new do
|
750
|
+
command "hello", "" do
|
751
|
+
eval_string.replace("6")
|
752
|
+
end
|
753
|
+
end
|
754
|
+
str_output = StringIO.new
|
755
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
756
|
+
str_output.string.should =~ /6/
|
757
|
+
end
|
758
|
+
|
759
|
+
|
760
|
+
it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
|
761
|
+
klass = Pry::CommandSet.new do
|
762
|
+
command "hello", "", :keep_retval => true do
|
763
|
+
eval_string.replace("6")
|
764
|
+
7
|
765
|
+
end
|
766
|
+
end
|
767
|
+
str_output = StringIO.new
|
768
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
769
|
+
str_output.string.should =~ /7/
|
770
|
+
str_output.string.should.not =~ /6/
|
771
|
+
end
|
772
|
+
|
773
|
+
it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
|
774
|
+
klass = Pry::CommandSet.new do
|
775
|
+
command "hello", "", :keep_retval => true do
|
776
|
+
5
|
777
|
+
end
|
778
|
+
end
|
779
|
+
str_output = StringIO.new
|
780
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
781
|
+
str_output.string.should =~ /5/
|
782
|
+
end
|
783
|
+
|
784
|
+
|
710
785
|
it 'should set the commands default, and the default should be overridable' do
|
711
786
|
klass = Pry::CommandSet.new do
|
712
787
|
command "hello" do
|
@@ -926,23 +1001,23 @@ describe Pry do
|
|
926
1001
|
|
927
1002
|
describe "pry return values" do
|
928
1003
|
it 'should return the target object' do
|
929
|
-
Pry.start(self, :input => StringIO.new("exit"), :output => Pry::NullOutput).should == self
|
1004
|
+
Pry.start(self, :input => StringIO.new("exit-all"), :output => Pry::NullOutput).should == self
|
930
1005
|
end
|
931
1006
|
|
932
|
-
it 'should return the parameter given to exit' do
|
933
|
-
Pry.start(self, :input => StringIO.new("exit 10"), :output => Pry::NullOutput).should == 10
|
1007
|
+
it 'should return the parameter given to exit-all' do
|
1008
|
+
Pry.start(self, :input => StringIO.new("exit-all 10"), :output => Pry::NullOutput).should == 10
|
934
1009
|
end
|
935
1010
|
|
936
|
-
it 'should return the parameter (multi word string) given to exit' do
|
937
|
-
Pry.start(self, :input => StringIO.new("exit \"john mair\""), :output => Pry::NullOutput).should == "john mair"
|
1011
|
+
it 'should return the parameter (multi word string) given to exit-all' do
|
1012
|
+
Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => Pry::NullOutput).should == "john mair"
|
938
1013
|
end
|
939
1014
|
|
940
|
-
it 'should return the parameter (function call) given to exit' do
|
941
|
-
Pry.start(self, :input => StringIO.new("exit 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
|
1015
|
+
it 'should return the parameter (function call) given to exit-all' do
|
1016
|
+
Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
|
942
1017
|
end
|
943
1018
|
|
944
|
-
it 'should return the parameter (self) given to exit' do
|
945
|
-
Pry.start("carl", :input => StringIO.new("exit self"), :output => Pry::NullOutput).should == "carl"
|
1019
|
+
it 'should return the parameter (self) given to exit-all' do
|
1020
|
+
Pry.start("carl", :input => StringIO.new("exit-all self"), :output => Pry::NullOutput).should == "carl"
|
946
1021
|
end
|
947
1022
|
end
|
948
1023
|
|
@@ -1047,8 +1122,82 @@ describe Pry do
|
|
1047
1122
|
end
|
1048
1123
|
end
|
1049
1124
|
|
1125
|
+
describe "view_clip used for displaying an object in a truncated format" do
|
1126
|
+
|
1127
|
+
VC_MAX_LENGTH = 60
|
1128
|
+
|
1129
|
+
describe "given an object with an #inspect string shorter than the maximum specified" do
|
1130
|
+
it "returns the #inspect string" do
|
1131
|
+
o = Object.new
|
1132
|
+
def o.inspect; "a" * VC_MAX_LENGTH; end
|
1133
|
+
|
1134
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
|
1135
|
+
end
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
describe "given an object with an #inspect string as long as the maximum specified" do
|
1139
|
+
it "returns the #inspect string" do
|
1140
|
+
o = Object.new
|
1141
|
+
def o.inspect; "a" * VC_MAX_LENGTH; end
|
1142
|
+
|
1143
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
|
1144
|
+
end
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
describe "given a regular object with an #inspect string longer than the maximum specified" do
|
1148
|
+
|
1149
|
+
describe "when the object is a regular one" do
|
1150
|
+
it "returns a string of the #<class name:object idish> format" do
|
1151
|
+
o = Object.new
|
1152
|
+
def o.inspect; "a" * (VC_MAX_LENGTH + 1); end
|
1153
|
+
|
1154
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /Object:0x\d+?/
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
|
1158
|
+
describe "when the object is a Class or a Module" do
|
1159
|
+
describe "without a name (usually a c = Class.new)" do
|
1160
|
+
it "returns a string of the #<class name:object idish> format" do
|
1161
|
+
c, m = Class.new, Module.new
|
1162
|
+
|
1163
|
+
Pry.view_clip(c, VC_MAX_LENGTH).should =~ /Class:0x.*?/
|
1164
|
+
Pry.view_clip(m, VC_MAX_LENGTH).should =~ /Module:0x.*?/
|
1165
|
+
end
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
describe "with a #name longer than the maximum specified" do
|
1169
|
+
it "returns a string of the #<class name:object idish> format" do
|
1170
|
+
c, m = Class.new, Module.new
|
1171
|
+
|
1172
|
+
|
1173
|
+
def c.name; "a" * (VC_MAX_LENGTH + 1); end
|
1174
|
+
def m.name; "a" * (VC_MAX_LENGTH + 1); end
|
1175
|
+
|
1176
|
+
Pry.view_clip(c, VC_MAX_LENGTH).should =~ /Class:0x.*?/
|
1177
|
+
Pry.view_clip(m, VC_MAX_LENGTH).should =~ /Module:0x.*?/
|
1178
|
+
end
|
1179
|
+
end
|
1180
|
+
|
1181
|
+
describe "with a #name shorter than or equal to the maximum specified" do
|
1182
|
+
it "returns a string of the #<class name:object idish> format" do
|
1183
|
+
c, m = Class.new, Module.new
|
1184
|
+
|
1185
|
+
def c.name; "a" * VC_MAX_LENGTH; end
|
1186
|
+
def m.name; "a" * VC_MAX_LENGTH; end
|
1187
|
+
|
1188
|
+
Pry.view_clip(c, VC_MAX_LENGTH).should == c.name
|
1189
|
+
Pry.view_clip(m, VC_MAX_LENGTH).should == m.name
|
1190
|
+
end
|
1191
|
+
end
|
1192
|
+
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
end
|
1196
|
+
|
1197
|
+
end
|
1198
|
+
|
1050
1199
|
it 'should set the hooks default, and the default should be overridable' do
|
1051
|
-
Pry.input = InputTester.new("exit")
|
1200
|
+
Pry.input = InputTester.new("exit-all")
|
1052
1201
|
Pry.hooks = {
|
1053
1202
|
:before_session => proc { |out,_| out.puts "HELLO" },
|
1054
1203
|
:after_session => proc { |out,_| out.puts "BYE" }
|
data/test/test_pry_history.rb
CHANGED
@@ -4,7 +4,7 @@ require 'tempfile'
|
|
4
4
|
describe Pry do
|
5
5
|
|
6
6
|
before do
|
7
|
-
|
7
|
+
Pry.history.clear
|
8
8
|
@hist = Tempfile.new(["tmp", ".pry_history"]).tap(&:close).path
|
9
9
|
File.open(@hist, 'w') {|f| f << "1\n2\n3\n" }
|
10
10
|
@old_hist = Pry.config.history.file
|
@@ -19,13 +19,13 @@ describe Pry do
|
|
19
19
|
|
20
20
|
describe ".load_history" do
|
21
21
|
it "should read the contents of the file" do
|
22
|
-
|
22
|
+
Pry.history.to_a[-2..-1].should === ["2", "3"]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe ".save_history" do
|
27
27
|
it "should include a trailing newline" do
|
28
|
-
|
28
|
+
Pry.history << "4"
|
29
29
|
Pry.save_history
|
30
30
|
File.read(@hist).should =~ /4\n\z/
|
31
31
|
end
|
@@ -37,45 +37,45 @@ describe Pry do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should append new lines to the file" do
|
40
|
-
|
40
|
+
Pry.history << "4"
|
41
41
|
Pry.save_history
|
42
42
|
File.read(@hist).should == "1\n2\n3\n4\n"
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should not clobber lines written by other Pry's in the meantime" do
|
46
|
-
|
46
|
+
Pry.history << "5"
|
47
47
|
File.open(@hist, 'a') {|f| f << "4\n" }
|
48
48
|
Pry.save_history
|
49
49
|
|
50
|
-
|
50
|
+
Pry.history.to_a[-3..-1].should == ["2", "3", "5"]
|
51
51
|
File.read(@hist).should == "1\n2\n3\n4\n5\n"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not delete lines from the file if this session's history was cleared" do
|
55
|
-
|
55
|
+
Pry.history.clear
|
56
56
|
Pry.save_history
|
57
57
|
File.read(@hist).should == "1\n2\n3\n"
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should save new lines that are added after the history was cleared" do
|
61
|
-
|
62
|
-
|
61
|
+
Pry.history.clear
|
62
|
+
Pry.history << "4"
|
63
63
|
|
64
64
|
# doing this twice as libedit on 1.8.7 has bugs and sometimes ignores the
|
65
65
|
# first line in history
|
66
|
-
|
66
|
+
Pry.history << "4"
|
67
67
|
Pry.save_history
|
68
68
|
File.read(@hist).should =~ /1\n2\n3\n4\n/
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should only append new lines the second time it is saved" do
|
72
|
-
|
72
|
+
Pry.history << "4"
|
73
73
|
Pry.save_history
|
74
74
|
File.open(@hist, 'a') {|f| f << "5\n" }
|
75
|
-
|
75
|
+
Pry.history << "6"
|
76
76
|
Pry.save_history
|
77
77
|
|
78
|
-
|
78
|
+
Pry.history.to_a[-4..-1].should == ["2", "3", "4", "6"]
|
79
79
|
File.read(@hist).should == "1\n2\n3\n4\n5\n6\n"
|
80
80
|
end
|
81
81
|
end
|