public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
[#108 state:resolved] Added specs for testing for empty and nil table data.  Now 
raises Prawn::Errors::EmptyTable
Gavin Stark (author)
Thu Nov 06 19:59:32 -0800 2008
commit  1c554c949357c3bd35160b1816849f7789fef9a9
tree    0c457e7a2e36f03b67f9f130209441158f2f641f
parent  286077da66c66c64e95380e5dce4f5cf5d6dea2f
...
37
38
39
 
 
 
40
 
 
 
 
41
42
43
...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
0
@@ -37,7 +37,14 @@ module Prawn
0
     #
0
     #   end
0
     #
0
+    #   Will raise <tt>Prawn::Errors::EmptyTable</tt> given 
0
+    #   a nil or empty <tt>data</tt> paramater.
0
+    #
0
     def table(data,options={})           
0
+      if data.nil? || data.empty?
0
+        raise Prawn::Errors::EmptyTable,
0
+          "data must be a non-empty, non-nil, two dimensional array of Prawn::Cells or strings"
0
+      end
0
       Prawn::Document::Table.new(data,self,options).draw
0
     end
0
 
...
39
40
41
 
 
 
 
42
43
44
...
39
40
41
42
43
44
45
46
47
48
0
@@ -39,6 +39,10 @@ module Prawn
0
      # This error is raised when table data is malformed
0
      #
0
      class InvalidTableData < StandardError; end 
0
+
0
+     # This error is raised when an empty or nil table is rendered
0
+     #
0
+     class EmptyTable < StandardError; end 
0
      
0
   end
0
 end   
...
109
110
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
113
114
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
0
@@ -109,6 +109,22 @@ describe "A table's content" do
0
       @pdf.table(data)
0
     }.should.not.raise
0
   end   
0
+
0
+  it "should raise an EmptyTableError with an empty table" do
0
+    lambda {
0
+      data = []
0
+      @pdf = Prawn::Document.new
0
+      @pdf.table(data)
0
+    }.should.raise( Prawn::Errors::EmptyTable )
0
+  end   
0
+
0
+  it "should raise an EmptyTableError with a nil table" do
0
+    lambda {
0
+      data = nil
0
+      @pdf = Prawn::Document.new
0
+      @pdf.table(data)
0
+    }.should.raise( Prawn::Errors::EmptyTable )
0
+  end   
0
   
0
   it "should paginate for large tables" do
0
     # 30 rows fit on the table with default setting, 31 exceed.

Comments