pdf-wrapper 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,127 +4,120 @@ require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  context "The PDF::Wrapper class" do
6
6
 
7
+ before(:each) { create_pdf }
8
+
7
9
  specify "should initilize with the correct default paper size and orientation" do
8
- pdf = PDF::Wrapper.new
9
- pdf.page_width.should eql(PDF::Wrapper::PAGE_SIZES[:A4].first)
10
- pdf.page_height.should eql(PDF::Wrapper::PAGE_SIZES[:A4].last)
10
+ @pdf.page_width.should eql(PDF::Wrapper::PAGE_SIZES[:A4].first)
11
+ @pdf.page_height.should eql(PDF::Wrapper::PAGE_SIZES[:A4].last)
11
12
  end
12
13
 
13
14
  specify "should initilize with the correct custom paper size" do
14
- pdf = PDF::Wrapper.new(:paper => :A0)
15
+ output = StringIO.new
16
+ pdf = PDF::Wrapper.new(output, :paper => :A0)
15
17
  pdf.page_width.should eql(PDF::Wrapper::PAGE_SIZES[:A0].first)
16
18
  pdf.page_height.should eql(PDF::Wrapper::PAGE_SIZES[:A0].last)
17
19
  end
18
20
 
19
21
  specify "should initilize with the correct custom orientation" do
20
- pdf = PDF::Wrapper.new(:paper => :A4, :orientation => :landscape)
22
+ output = StringIO.new
23
+ pdf = PDF::Wrapper.new(output, :paper => :A4, :orientation => :landscape)
21
24
  pdf.page_width.should eql(PDF::Wrapper::PAGE_SIZES[:A4].last)
22
25
  pdf.page_height.should eql(PDF::Wrapper::PAGE_SIZES[:A4].first)
23
26
  end
24
27
 
25
28
  specify "should raise an exception if an invalid orientation is requested" do
26
- lambda {pdf = PDF::Wrapper.new(:paper => :A4, :orientation => :fake)}.should raise_error(ArgumentError)
29
+ output = StringIO.new
30
+ lambda {pdf = PDF::Wrapper.new(output, :paper => :A4, :orientation => :fake)}.should raise_error(ArgumentError)
27
31
  end
28
32
 
29
33
  specify "should store sensible default text options" do
30
- pdf = PDF::Wrapper.new
31
- pdf.default_text_options.should be_a_kind_of(Hash)
34
+ @pdf.default_text_options.should be_a_kind_of(Hash)
32
35
  end
33
36
 
34
37
  specify "should initilize with the correct default margins (5% of the page)" do
35
- pdf = PDF::Wrapper.new
36
- pdf.margin_left.should eql((PDF::Wrapper::PAGE_SIZES[:A4].first * 0.05).ceil)
37
- pdf.margin_right.should eql((PDF::Wrapper::PAGE_SIZES[:A4].first * 0.05).ceil)
38
- pdf.margin_top.should eql((PDF::Wrapper::PAGE_SIZES[:A4].last * 0.05).ceil)
39
- pdf.margin_bottom.should eql((PDF::Wrapper::PAGE_SIZES[:A4].last * 0.05).ceil)
38
+ @pdf.margin_left.should eql((PDF::Wrapper::PAGE_SIZES[:A4].first * 0.05).ceil)
39
+ @pdf.margin_right.should eql((PDF::Wrapper::PAGE_SIZES[:A4].first * 0.05).ceil)
40
+ @pdf.margin_top.should eql((PDF::Wrapper::PAGE_SIZES[:A4].last * 0.05).ceil)
41
+ @pdf.margin_bottom.should eql((PDF::Wrapper::PAGE_SIZES[:A4].last * 0.05).ceil)
40
42
  end
41
43
 
42
44
  specify "should initilize with the correct default text and colour settings" do
43
- pdf = PDF::Wrapper.new
44
- pdf.instance_variable_get("@default_font").should eql("Sans Serif")
45
- pdf.instance_variable_get("@default_font_size").should eql(16)
45
+ @pdf.instance_variable_get("@default_font").should eql("Sans Serif")
46
+ @pdf.instance_variable_get("@default_font_size").should eql(16)
46
47
  end
47
48
 
48
49
  specify "should be able to change the default font" do
49
- pdf = PDF::Wrapper.new
50
- pdf.font("Arial")
51
- pdf.instance_variable_get("@default_font").should eql("Arial")
50
+ @pdf.font("Arial")
51
+ @pdf.instance_variable_get("@default_font").should eql("Arial")
52
52
  end
53
53
 
54
54
  specify "should be able to change the default font size" do
55
- pdf = PDF::Wrapper.new
56
- pdf.font_size(24)
57
- pdf.instance_variable_get("@default_font_size").should eql(24)
55
+ @pdf.font_size(24)
56
+ @pdf.instance_variable_get("@default_font_size").should eql(24)
58
57
  end
59
58
 
60
59
  specify "should initialize with the cursor at the top left of the body of the page" do
61
- pdf = PDF::Wrapper.new
62
- x,y = pdf.current_point
63
- x.to_i.should eql(pdf.margin_left)
64
- y.to_i.should eql(pdf.margin_top)
60
+ x,y = @pdf.current_point
61
+ x.to_i.should eql(@pdf.margin_left)
62
+ y.to_i.should eql(@pdf.margin_top)
65
63
  end
66
64
 
67
65
  specify "should calculate the absolute coordinates for the margins correctly" do
68
- pdf = PDF::Wrapper.new
69
- pdf.absolute_left_margin.should eql(pdf.margin_left)
70
- pdf.absolute_right_margin.should eql(pdf.page_width - pdf.margin_right)
71
- pdf.absolute_top_margin.should eql(pdf.margin_top)
72
- pdf.absolute_bottom_margin.should eql(pdf.page_height - pdf.margin_bottom)
66
+ @pdf.absolute_left_margin.should eql(@pdf.margin_left)
67
+ @pdf.absolute_right_margin.should eql(@pdf.page_width - @pdf.margin_right)
68
+ @pdf.absolute_top_margin.should eql(@pdf.margin_top)
69
+ @pdf.absolute_bottom_margin.should eql(@pdf.page_height - @pdf.margin_bottom)
73
70
  end
74
71
 
75
72
  specify "should calculate various useful page coordinates correctly" do
76
- pdf = PDF::Wrapper.new
77
- pdf.absolute_x_middle.should eql(PDF::Wrapper::PAGE_SIZES[:A4].first / 2)
78
- pdf.absolute_y_middle.should eql(PDF::Wrapper::PAGE_SIZES[:A4].last / 2)
79
- pdf.body_width.should eql(pdf.page_width - pdf.margin_left - pdf.margin_right)
80
- pdf.body_height.should eql(pdf.page_height - pdf.margin_top - pdf.margin_bottom)
81
- pdf.body_x_middle.should eql(pdf.margin_left + (pdf.body_width/ 2))
82
- pdf.body_y_middle.should eql(pdf.margin_top + (pdf.body_height/ 2))
83
- pdf.points_to_bottom_margin(300).should eql(pdf.absolute_bottom_margin - 300)
84
- pdf.points_to_right_margin(300).should eql(pdf.absolute_right_margin - 300)
73
+ @pdf.absolute_x_middle.should eql(PDF::Wrapper::PAGE_SIZES[:A4].first / 2)
74
+ @pdf.absolute_y_middle.should eql(PDF::Wrapper::PAGE_SIZES[:A4].last / 2)
75
+ @pdf.body_width.should eql(@pdf.page_width - @pdf.margin_left - @pdf.margin_right)
76
+ @pdf.body_height.should eql(@pdf.page_height - @pdf.margin_top - @pdf.margin_bottom)
77
+ @pdf.body_x_middle.should eql(@pdf.margin_left + (@pdf.body_width/ 2))
78
+ @pdf.body_y_middle.should eql(@pdf.margin_top + (@pdf.body_height/ 2))
79
+ @pdf.points_to_bottom_margin(300).should eql(@pdf.absolute_bottom_margin - 300)
80
+ @pdf.points_to_right_margin(300).should eql(@pdf.absolute_right_margin - 300)
85
81
  end
86
82
 
87
83
  specify "should be able to move the cursor to any arbitary point on the canvas" do
88
- pdf = PDF::Wrapper.new
89
- pdf.move_to(100,100)
90
- x,y = pdf.current_point
84
+ @pdf.move_to(100,100)
85
+ x,y = @pdf.current_point
91
86
  x.to_i.should eql(100)
92
87
  y.to_i.should eql(100)
93
88
  end
94
89
 
95
90
  specify "should be able to shift the y position of the cursor using pad" do
96
- pdf = PDF::Wrapper.new
97
- pdf.move_to(100,100)
98
- newy = pdf.pad(25)
99
- x,y = pdf.current_point
91
+ @pdf.move_to(100,100)
92
+ newy = @pdf.pad(25)
93
+ x,y = @pdf.current_point
100
94
  x.to_i.should eql(100)
101
95
  y.to_i.should eql(125)
102
96
  newy.should eql(125.0)
103
97
  end
104
98
 
105
99
  specify "should add additional pages at the users request" do
106
- pdf = PDF::Wrapper.new
107
- pdf.move_to(100,100)
108
- pdf.start_new_page
109
- x,y = pdf.current_point
110
- x.to_i.should eql(pdf.margin_left)
111
- y.to_i.should eql(pdf.margin_top)
100
+ @pdf.move_to(100,100)
101
+ @pdf.start_new_page
102
+ x,y = @pdf.current_point
103
+ x.to_i.should eql(@pdf.margin_left)
104
+ y.to_i.should eql(@pdf.margin_top)
105
+ @pdf.finish
112
106
 
113
107
  # verify the output
114
108
  receiver = PageReceiver.new
115
- reader = PDF::Reader.string(pdf.render, receiver)
109
+ reader = PDF::Reader.string(@output.string, receiver)
116
110
  receiver.pages.should eql(2)
117
111
  end
118
112
 
119
113
 
120
114
  specify "should leave the cursor in the bottom left of a layout when new text is added" do
121
- pdf = PDF::Wrapper.new
122
- x, y = pdf.current_point
115
+ x, y = @pdf.current_point
123
116
  str = "Chunky Bacon!!"
124
117
  opts = {:font_size => 16, :font => "Sans Serif", :alignment => :left, :justify => false }
125
- height = pdf.text_height(str, pdf.page_width, opts)
126
- pdf.text(str,opts)
127
- newx, newy = pdf.current_point
118
+ height = @pdf.text_height(str, @pdf.page_width, opts)
119
+ @pdf.text(str,opts)
120
+ newx, newy = @pdf.current_point
128
121
 
129
122
  newx.should eql(x)
130
123
  # the top of our text box, plus its height
@@ -134,13 +127,14 @@ context "The PDF::Wrapper class" do
134
127
  specify "should be able to render to a file" do
135
128
  # generate a PDF
136
129
  msg = "Chunky Bacon"
137
- pdf = PDF::Wrapper.new
138
- pdf.text msg
139
130
 
140
131
  # write the PDF to a temp file
141
132
  tmp = Tempfile.open("siftr")
142
133
  tmp.close
143
- pdf.render_file(tmp.path)
134
+
135
+ pdf = PDF::Wrapper.new(tmp.path)
136
+ pdf.text msg
137
+ pdf.finish
144
138
 
145
139
  # ensure an actual PDF was written out
146
140
  File.open(tmp.path, "r") do |f|
@@ -152,27 +146,26 @@ context "The PDF::Wrapper class" do
152
146
  end
153
147
 
154
148
  specify "should be able to determine if a requested colour is valid or not" do
155
- pdf = PDF::Wrapper.new
156
- pdf.validate_color(:black).should be_true
157
- pdf.validate_color([1,0,0]).should be_true
158
- pdf.validate_color([1,0,0,0.5]).should be_true
159
- lambda { pdf.validate_color(:ponies)}.should raise_error(ArgumentError)
160
- lambda { pdf.validate_color([1])}.should raise_error(ArgumentError)
161
- lambda { pdf.validate_color([1000, 255, 0])}.should raise_error(ArgumentError)
149
+ @pdf.validate_color(:black).should be_true
150
+ @pdf.validate_color([1,0,0]).should be_true
151
+ @pdf.validate_color([1,0,0,0.5]).should be_true
152
+ lambda { @pdf.validate_color(:ponies)}.should raise_error(ArgumentError)
153
+ lambda { @pdf.validate_color([1])}.should raise_error(ArgumentError)
154
+ lambda { @pdf.validate_color([1000, 255, 0])}.should raise_error(ArgumentError)
162
155
  end
163
156
 
164
157
  specify "should be able to add repeating elements to :all pages" do
165
158
  test_str = "repeating"
166
159
 
167
- pdf = PDF::Wrapper.new
168
- pdf.repeating_element(:all) { |page| page.text test_str }
160
+ @pdf.repeating_element(:all) { |page| page.text test_str }
169
161
 
170
- pdf.start_new_page
171
- pdf.start_new_page
172
- pdf.start_new_page
162
+ @pdf.start_new_page
163
+ @pdf.start_new_page
164
+ @pdf.start_new_page
165
+ @pdf.finish
173
166
 
174
167
  receiver = PageTextReceiver.new
175
- reader = PDF::Reader.string(pdf.render, receiver)
168
+ reader = PDF::Reader.string(@output.string, receiver)
176
169
 
177
170
  receiver.content.size.should eql(4)
178
171
  receiver.content[0].should eql(test_str)
@@ -184,15 +177,15 @@ context "The PDF::Wrapper class" do
184
177
  specify "should be able to add repeating elements to :odd pages" do
185
178
  test_str = "repeating"
186
179
 
187
- pdf = PDF::Wrapper.new
188
- pdf.repeating_element(:odd) { |page| page.text test_str }
180
+ @pdf.repeating_element(:odd) { |page| page.text test_str }
189
181
 
190
- pdf.start_new_page
191
- pdf.start_new_page
192
- pdf.start_new_page
182
+ @pdf.start_new_page
183
+ @pdf.start_new_page
184
+ @pdf.start_new_page
185
+ @pdf.finish
193
186
 
194
187
  receiver = PageTextReceiver.new
195
- reader = PDF::Reader.string(pdf.render, receiver)
188
+ reader = PDF::Reader.string(@output.string, receiver)
196
189
 
197
190
  receiver.content.size.should eql(4)
198
191
  receiver.content[0].should eql(test_str)
@@ -204,15 +197,15 @@ context "The PDF::Wrapper class" do
204
197
  specify "should be able to add repeating elements to :even pages" do
205
198
  test_str = "repeating"
206
199
 
207
- pdf = PDF::Wrapper.new
208
- pdf.repeating_element(:even) { |page| page.text test_str }
200
+ @pdf.repeating_element(:even) { |page| page.text test_str }
209
201
 
210
- pdf.start_new_page
211
- pdf.start_new_page
212
- pdf.start_new_page
202
+ @pdf.start_new_page
203
+ @pdf.start_new_page
204
+ @pdf.start_new_page
205
+ @pdf.finish
213
206
 
214
207
  receiver = PageTextReceiver.new
215
- reader = PDF::Reader.string(pdf.render, receiver)
208
+ reader = PDF::Reader.string(@output.string, receiver)
216
209
 
217
210
  receiver.content.size.should eql(4)
218
211
  receiver.content[0].should eql("")
@@ -224,15 +217,15 @@ context "The PDF::Wrapper class" do
224
217
  specify "should be able to add repeating elements to a range of pages" do
225
218
  test_str = "repeating"
226
219
 
227
- pdf = PDF::Wrapper.new
228
- pdf.repeating_element((2..3)) { |page| page.text test_str }
220
+ @pdf.repeating_element((2..3)) { |page| page.text test_str }
229
221
 
230
- pdf.start_new_page
231
- pdf.start_new_page
232
- pdf.start_new_page
222
+ @pdf.start_new_page
223
+ @pdf.start_new_page
224
+ @pdf.start_new_page
225
+ @pdf.finish
233
226
 
234
227
  receiver = PageTextReceiver.new
235
- reader = PDF::Reader.string(pdf.render, receiver)
228
+ reader = PDF::Reader.string(@output.string, receiver)
236
229
 
237
230
  receiver.content.size.should eql(4)
238
231
  receiver.content[0].should eql("")
@@ -244,15 +237,15 @@ context "The PDF::Wrapper class" do
244
237
  specify "should be able to add repeating elements to a single page" do
245
238
  test_str = "repeating"
246
239
 
247
- pdf = PDF::Wrapper.new
248
- pdf.repeating_element(2) { |page| page.text test_str }
240
+ @pdf.repeating_element(2) { |page| page.text test_str }
249
241
 
250
- pdf.start_new_page
251
- pdf.start_new_page
252
- pdf.start_new_page
242
+ @pdf.start_new_page
243
+ @pdf.start_new_page
244
+ @pdf.start_new_page
245
+ @pdf.finish
253
246
 
254
247
  receiver = PageTextReceiver.new
255
- reader = PDF::Reader.string(pdf.render, receiver)
248
+ reader = PDF::Reader.string(@output.string, receiver)
256
249
 
257
250
  receiver.content.size.should eql(4)
258
251
  receiver.content[0].should eql("")
@@ -264,15 +257,15 @@ context "The PDF::Wrapper class" do
264
257
  specify "should be able to add repeating elements to an array of pages" do
265
258
  test_str = "repeating"
266
259
 
267
- pdf = PDF::Wrapper.new
268
- pdf.repeating_element([1,3,4]) { |page| page.text test_str }
260
+ @pdf.repeating_element([1,3,4]) { |page| page.text test_str }
269
261
 
270
- pdf.start_new_page
271
- pdf.start_new_page
272
- pdf.start_new_page
262
+ @pdf.start_new_page
263
+ @pdf.start_new_page
264
+ @pdf.start_new_page
265
+ @pdf.finish
273
266
 
274
267
  receiver = PageTextReceiver.new
275
- reader = PDF::Reader.string(pdf.render, receiver)
268
+ reader = PDF::Reader.string(@output.string, receiver)
276
269
 
277
270
  receiver.content.size.should eql(4)
278
271
  receiver.content[0].should eql(test_str)
@@ -286,9 +279,8 @@ context "The PDF::Wrapper class" do
286
279
  specify "should not allow a new page to be started while adding repeating elements" do
287
280
  test_str = "repeating"
288
281
 
289
- pdf = PDF::Wrapper.new
290
282
  lambda do
291
- pdf.repeating_element([1,3,4]) do |page|
283
+ @pdf.repeating_element([1,3,4]) do |page|
292
284
  page.text test_str
293
285
  page.start_new_page
294
286
  end
@@ -297,120 +289,120 @@ context "The PDF::Wrapper class" do
297
289
  end
298
290
 
299
291
  specify "should leave the cursor on the bottom left corner of an object when using functions with optional positioning [func(data, opts)]" do
300
- pdf = PDF::Wrapper.new
301
- origx, origy = pdf.current_point
292
+ origx, origy = @pdf.current_point
302
293
 
303
294
  # text()
304
- pdf.text("Page #{pdf.page}!", :left => pdf.margin_left, :top => pdf.margin_top, :font_size => 18)
305
- x, y = pdf.current_point
295
+ @pdf.text("Page #{@pdf.page}!", :left => @pdf.margin_left, :top => @pdf.margin_top, :font_size => 18)
296
+ x, y = @pdf.current_point
306
297
  x.should eql(origx)
307
298
  y.should eql(origy + 27)
308
299
 
309
300
  # image() - palms it's works out to helper functions, so we have to check them individually
310
301
 
311
302
  # TODO: work out why rcov segfaults when i use the draw_pdf method
312
- #origx, origy = pdf.current_point
313
- #pdf.draw_pdf(File.dirname(__FILE__) + "/data/utf8-long.pdf", :height => 50)
314
- #x, y = pdf.current_point
303
+ #origx, origy = @pdf.current_point
304
+ #@pdf.draw_pdf(File.dirname(__FILE__) + "/data/utf8-long.pdf", :height => 50)
305
+ #x, y = @pdf.current_point
315
306
  #x.should eql(origx)
316
307
  #y.should eql(origy + 50)
317
308
 
318
- origx, origy = pdf.current_point
319
- pdf.draw_pixbuf(File.dirname(__FILE__) + "/data/zits.gif", :height => 50)
320
- x, y = pdf.current_point
309
+ origx, origy = @pdf.current_point
310
+ @pdf.draw_pixbuf(File.dirname(__FILE__) + "/data/zits.gif", :height => 50)
311
+ x, y = @pdf.current_point
321
312
  x.should eql(origx)
322
313
  y.should eql(origy + 50)
323
314
 
324
- origx, origy = pdf.current_point
325
- pdf.draw_png(File.dirname(__FILE__) + "/data/google.png", :height => 200)
326
- x, y = pdf.current_point
315
+ origx, origy = @pdf.current_point
316
+ @pdf.draw_png(File.dirname(__FILE__) + "/data/google.png", :height => 200)
317
+ x, y = @pdf.current_point
327
318
  x.should eql(origx)
328
319
  y.should eql(origy + 200)
329
320
 
330
- origx, origy = pdf.current_point
331
- pdf.draw_svg(File.dirname(__FILE__) + "/data/orc.svg", :height => 100)
332
- x, y = pdf.current_point
321
+ origx, origy = @pdf.current_point
322
+ @pdf.draw_svg(File.dirname(__FILE__) + "/data/orc.svg", :height => 100)
323
+ x, y = @pdf.current_point
333
324
  x.should eql(origx)
334
325
  y.should eql(origy + 100)
335
326
  end
336
327
 
337
328
  specify "should leave the cursor unmodified when using functions with compulsory positioning [func(data, x, y, w, h, opts)]" do
338
- pdf = PDF::Wrapper.new
339
- origx, origy = pdf.current_point
329
+ origx, origy = @pdf.current_point
340
330
 
341
331
  # cell()
342
- pdf.cell("test", 100, 100, 100, 100)
343
- x, y = pdf.current_point
332
+ @pdf.cell("test", 100, 100, 100, 100)
333
+ x, y = @pdf.current_point
344
334
  x.should eql(origx)
345
335
  y.should eql(origy)
346
336
 
347
337
  # circle()
348
- pdf.circle(200, 200, 50)
349
- x, y = pdf.current_point
338
+ @pdf.circle(200, 200, 50)
339
+ x, y = @pdf.current_point
350
340
  x.should eql(origx)
351
341
  y.should eql(origy)
352
342
 
353
343
  # line()
354
- pdf.line(300, 200, 350, 300)
355
- x, y = pdf.current_point
344
+ @pdf.line(300, 200, 350, 300)
345
+ x, y = @pdf.current_point
356
346
  x.should eql(origx)
357
347
  y.should eql(origy)
358
348
 
359
349
  # rectangle()
360
- pdf.rectangle(200, 400, 100, 100)
361
- x, y = pdf.current_point
350
+ @pdf.rectangle(200, 400, 100, 100)
351
+ x, y = @pdf.current_point
362
352
  x.should eql(origx)
363
353
  y.should eql(origy)
364
354
  end
365
355
 
366
356
  specify "should maintain an internal counter of pages" do
367
- pdf = PDF::Wrapper.new
368
- pdf.page.should eql(1)
369
- pdf.start_new_page
370
- pdf.page.should eql(2)
371
- pdf.start_new_page(:pageno => 50)
372
- pdf.page.should eql(50)
373
- end
374
-
375
- specify "should raise an ArgumentError when a function that accepts an options hash is passed an unreognised option" do
376
- lambda { PDF::Wrapper.new(:ponies => true)}.should raise_error(ArgumentError)
377
- pdf = PDF::Wrapper.new
378
- lambda { pdf.cell("test",100,100,100,100, :ponies => true)}.should raise_error(ArgumentError)
379
- lambda { pdf.table([[1,2]], :ponies => true)}.should raise_error(ArgumentError)
380
- lambda { pdf.text("test", :ponies => true)}.should raise_error(ArgumentError)
381
- lambda { pdf.text("test", :ponies => true)}.should raise_error(ArgumentError)
382
- lambda { pdf.text_height("test", 100, :ponies => true)}.should raise_error(ArgumentError)
383
- lambda { pdf.circle(100,100,100, :ponies => true)}.should raise_error(ArgumentError)
384
- lambda { pdf.line(100,100,200,200, :ponies => true)}.should raise_error(ArgumentError)
385
- lambda { pdf.rectangle(100,100,100,100, :ponies => true)}.should raise_error(ArgumentError)
386
- lambda { pdf.start_new_page(:ponies => true)}.should raise_error(ArgumentError)
387
- lambda { pdf.image(File.dirname(__FILE__) + "/data/orc.svg", :ponies => true)}.should raise_error(ArgumentError)
357
+ @pdf.page.should eql(1)
358
+ @pdf.start_new_page
359
+ @pdf.page.should eql(2)
360
+ @pdf.start_new_page(:pageno => 50)
361
+ @pdf.page.should eql(50)
362
+ end
363
+
364
+ specify "should raise an ArgumentError when a function that accepts an options hash is passed an unrecognised option" do
365
+ output = StringIO.new
366
+ lambda { PDF::Wrapper.new(output, :ponies => true)}.should raise_error(ArgumentError)
367
+ lambda { @pdf.cell("test",100,100,100,100, :ponies => true)}.should raise_error(ArgumentError)
368
+ lambda { @pdf.table([[1,2]], :ponies => true)}.should raise_error(ArgumentError)
369
+ lambda { @pdf.text("test", :ponies => true)}.should raise_error(ArgumentError)
370
+ lambda { @pdf.text("test", :ponies => true)}.should raise_error(ArgumentError)
371
+ lambda { @pdf.text_height("test", 100, :ponies => true)}.should raise_error(ArgumentError)
372
+ lambda { @pdf.circle(100,100,100, :ponies => true)}.should raise_error(ArgumentError)
373
+ lambda { @pdf.line(100,100,200,200, :ponies => true)}.should raise_error(ArgumentError)
374
+ lambda { @pdf.rectangle(100,100,100,100, :ponies => true)}.should raise_error(ArgumentError)
375
+ lambda { @pdf.start_new_page(:ponies => true)}.should raise_error(ArgumentError)
376
+ lambda { @pdf.image(File.dirname(__FILE__) + "/data/orc.svg", :ponies => true)}.should raise_error(ArgumentError)
388
377
  end
389
378
 
390
379
  specify "should allow an existing file to be used as a template for page 1" do
391
- pdf = PDF::Wrapper.new(:paper => :A4, :template => File.dirname(__FILE__) + "/data/orc.svg")
380
+ output = StringIO.new
381
+ pdf = PDF::Wrapper.new(output, :paper => :A4, :template => File.dirname(__FILE__) + "/data/orc.svg")
392
382
  pdf.start_new_page
383
+ pdf.finish
393
384
 
394
385
  receiver = PageSizeReceiver.new
395
- reader = PDF::Reader.string(pdf.render, receiver)
386
+ reader = PDF::Reader.string(output.string, receiver)
396
387
 
397
388
  receiver.pages[0].should eql([0.0, 0.0, 734.0, 772.0])
398
389
  receiver.pages[1].should eql([0.0, 0.0, 595.28, 841.89])
399
390
  end
400
391
 
401
392
  specify "should allow an existing file to be used as a template for page 2" do
402
- pdf = PDF::Wrapper.new(:paper => :A4)
403
- pdf.start_new_page(:template => File.dirname(__FILE__) + "/data/orc.svg")
393
+ @pdf.start_new_page(:template => File.dirname(__FILE__) + "/data/orc.svg")
394
+ @pdf.finish
404
395
 
405
396
  receiver = PageSizeReceiver.new
406
- reader = PDF::Reader.string(pdf.render, receiver)
397
+ reader = PDF::Reader.string(@output.string, receiver)
407
398
 
408
399
  receiver.pages[0].should eql([0.0, 0.0, 595.28, 841.89])
409
400
  receiver.pages[1].should eql([0.0, 0.0, 734.0, 772.0])
410
401
  end
411
402
 
412
403
  specify "should correctly convert a user x co-ordinate to device" do
413
- pdf = PDF::Wrapper.new(:paper => :A4, :margin_left => 40)
404
+ output = StringIO.new
405
+ pdf = PDF::Wrapper.new(output, :paper => :A4, :margin_left => 40)
414
406
 
415
407
  pdf.user_x_to_device_x(10).should eql(10.0)
416
408
 
@@ -422,7 +414,8 @@ context "The PDF::Wrapper class" do
422
414
  end
423
415
 
424
416
  specify "should correctly convert a user y co-ordinate to device" do
425
- pdf = PDF::Wrapper.new(:paper => :A4, :margin_top => 40)
417
+ output = StringIO.new
418
+ pdf = PDF::Wrapper.new(output, :paper => :A4, :margin_top => 40)
426
419
 
427
420
  pdf.user_y_to_device_y(10).should eql(10.0)
428
421
 
@@ -434,7 +427,8 @@ context "The PDF::Wrapper class" do
434
427
  end
435
428
 
436
429
  specify "should correctly convert a device x co-ordinate to user" do
437
- pdf = PDF::Wrapper.new(:paper => :A4, :margin_left => 40)
430
+ output = StringIO.new
431
+ pdf = PDF::Wrapper.new(output, :paper => :A4, :margin_left => 40)
438
432
 
439
433
  pdf.device_x_to_user_x(10).should eql(10.0)
440
434
 
@@ -445,7 +439,8 @@ context "The PDF::Wrapper class" do
445
439
  end
446
440
 
447
441
  specify "should correctly convert a device y co-ordinate to user" do
448
- pdf = PDF::Wrapper.new(:paper => :A4, :margin_top => 40)
442
+ output = StringIO.new
443
+ pdf = PDF::Wrapper.new(output, :paper => :A4, :margin_top => 40)
449
444
 
450
445
  pdf.device_y_to_user_y(10).should eql(10.0)
451
446
 
@@ -455,18 +450,10 @@ context "The PDF::Wrapper class" do
455
450
  end
456
451
  end
457
452
 
458
- specify "should allow Wrapper#render to be called multiple times" do
459
- pdf = PDF::Wrapper.new
460
- pdf.text "Hi!"
461
- pdf.render.should be_a_kind_of(String)
462
- pdf.render.should be_a_kind_of(String)
463
- end
464
-
465
453
  specify "should be aware of when the underlying PDFSurface has been finished" do
466
- pdf = PDF::Wrapper.new
467
- pdf.text "Hi!"
468
- pdf.finished?.should be_false
469
- pdf.render
470
- pdf.finished?.should be_true
454
+ @pdf.text "Hi!"
455
+ @pdf.finished?.should be_false
456
+ @pdf.finish
457
+ @pdf.finished?.should be_true
471
458
  end
472
459
  end