public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
Specs for Kernel#p behaviour.

* Args vs. no args.
* Record separator is not taken into account.
rue (author)
Tue Apr 15 17:07:48 -0700 2008
commit  e1406b19c51bfca5f6936d143087043316c68c13
tree    42647805d55edeee6f66594774be168e78adb626
parent  30c717e1736b65a852df501f71e320599fc17786
...
2
3
4
 
 
 
 
 
 
 
 
5
6
7
...
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
0
@@ -2,6 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
0
 require File.dirname(__FILE__) + '/fixtures/classes'
0
 
0
 describe "Kernel#p" do
0
+ before :all do
0
+ @rs_f, @rs_b, @rs_c = $/, $\, $,
0
+ end
0
+
0
+ after :each do
0
+ $/, $\, $, = @rs_f, @rs_b, @rs_c
0
+ end
0
+
0
   it "is a private method" do
0
     Kernel.private_instance_methods.should include("p")
0
   end
0
@@ -27,6 +35,38 @@ describe "Kernel#p" do
0
     end
0
   end
0
 
0
+ it "prints obj.inspect followed by system record separator (usually \\n) for each argument given" do
0
+ o = mock("Inspector Gadget")
0
+ o.should_receive(:inspect).any_number_of_times.and_return "Next time, Gadget, NEXT TIME!"
0
+
0
+ lambda { p(o) }.should output("Next time, Gadget, NEXT TIME!\n")
0
+ lambda { p(*[o]) }.should output("Next time, Gadget, NEXT TIME!\n")
0
+ lambda { p(*[o, o]) }.should output("Next time, Gadget, NEXT TIME!\nNext time, Gadget, NEXT TIME!\n")
0
+ lambda { p([o])}.should output("[#{o.inspect}]\n")
0
+ end
0
+
0
+ it "is not affected by setting $\\, $/ or $," do
0
+ o = mock("Inspector Gadget")
0
+ o.should_receive(:inspect).any_number_of_times.and_return "Next time, Gadget, NEXT TIME!"
0
+
0
+ $, = " *helicopter sound*\n"
0
+ lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
0
+
0
+ $\ = " *helicopter sound*\n"
0
+ lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
0
+
0
+ $/ = " *helicopter sound*\n"
0
+ lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
0
+ end
0
+
0
+ it "prints nothing if no argument is given" do
0
+ lambda { p }.should output("")
0
+ end
0
+
0
+ it "prints nothing if called splatting an empty Array" do
0
+ lambda { p(*[]) }.should output("")
0
+ end
0
+
0
 =begin Not sure how to spec this, but wanted to note the behavior here
0
   it "does not flush if receiver is not a TTY or a File" do
0
   end

Comments

    No one has commented yet.