public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
Added cursory tests for content, this should be enough for a rough coverage net 
over tables, we'll fill in more specs as needed. [#32 state:resolved]
sandal (author)
Wed Jun 25 11:24:19 -0700 2008
commit  dce12d8675c91a2e3fd6c3eed7e6e88394ce17da
tree    0842de7d5ac27c1548231f5dcbefba0c92c2797b
parent  46606bf974f0954fe9d180c0dc7b9dbba7277a86
...
74
75
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
0
@@ -74,3 +74,57 @@ describe "A table's width" do
0
   end
0
 
0
 end
0
+
0
+class TableTextObserver
0
+  attr_accessor :font_settings, :size, :strings
0
+            
0
+  def initialize     
0
+    @font_settings = []
0
+    @fonts = {}
0
+    @strings = []
0
+  end
0
+  
0
+  def resource_font(*params)
0
+    @fonts[params[0]] = params[1].basefont
0
+  end
0
+
0
+  def set_text_font_and_size(*params)     
0
+    @font_settings << { :name => @fonts[params[0]], :size => params[1] }
0
+  end     
0
+  
0
+  def show_text(*params)
0
+    @strings << params[0]
0
+  end
0
+end
0
+
0
+
0
+describe "A table's content" do
0
+
0
+  it "should output content cell by cell, row by row" do
0
+    data = [["foo","bar"],["baz","bang"]]
0
+    @pdf = Prawn::Document.new
0
+    @pdf.table(data)
0
+    output = observer(TableTextObserver)
0
+    output.strings.should == data.flatten
0
+  end
0
+
0
+  it "should add headers to output when specified" do
0
+    data = [["foo","bar"],["baz","bang"]]
0
+    headers = %w[a b]
0
+    @pdf = Prawn::Document.new
0
+    @pdf.table(data, :headers => headers)
0
+    output = observer(TableTextObserver)
0
+    output.strings.should == headers + data.flatten
0
+  end
0
+
0
+  it "should repeat headers across pages" do
0
+    data = [["foo","bar"]]*30
0
+    headers = ["baz","foobar"]
0
+    @pdf = Prawn::Document.new
0
+    @pdf.table(data, :headers => headers)
0
+    output = observer(TableTextObserver)
0
+    output.strings.should == headers + data.flatten[0..-3] + headers +
0
+      data.flatten[-2..-1]
0
+  end
0
+    
0
+end

Comments