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.
data/specs/image_spec.rb CHANGED
@@ -3,38 +3,37 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  context "The PDF::Wrapper class" do
6
+
7
+ before(:each) { create_pdf }
8
+
6
9
  specify "should be able to detect the filetype of an image" do
7
- pdf = PDF::Wrapper.new
8
- pdf.detect_image_type(File.dirname(__FILE__) + "/data/google.png").should eql(:png)
9
- pdf.detect_image_type(File.dirname(__FILE__) + "/data/zits.gif").should eql(:gif)
10
- pdf.detect_image_type(File.dirname(__FILE__) + "/data/orc.svg").should eql(:svg)
11
- pdf.detect_image_type(File.dirname(__FILE__) + "/data/utf8-long.pdf").should eql(:pdf)
12
- pdf.detect_image_type(File.dirname(__FILE__) + "/data/shipsail.jpg").should eql(:jpg)
10
+ @pdf.detect_image_type(File.dirname(__FILE__) + "/data/google.png").should eql(:png)
11
+ @pdf.detect_image_type(File.dirname(__FILE__) + "/data/zits.gif").should eql(:gif)
12
+ @pdf.detect_image_type(File.dirname(__FILE__) + "/data/orc.svg").should eql(:svg)
13
+ @pdf.detect_image_type(File.dirname(__FILE__) + "/data/utf8-long.pdf").should eql(:pdf)
14
+ @pdf.detect_image_type(File.dirname(__FILE__) + "/data/shipsail.jpg").should eql(:jpg)
13
15
  end
14
16
 
15
17
  specify "should be able to determine image dimensions correctly" do
16
- pdf = PDF::Wrapper.new
17
- pdf.image_dimensions(File.dirname(__FILE__) + "/data/google.png").should eql([166,55])
18
- pdf.image_dimensions(File.dirname(__FILE__) + "/data/zits.gif").should eql([525,167])
19
- pdf.image_dimensions(File.dirname(__FILE__) + "/data/orc.svg").should eql([734, 772])
20
- pdf.image_dimensions(File.dirname(__FILE__) + "/data/utf8-long.pdf").map{ |d| d.to_i}.should eql([595,841])
21
- pdf.image_dimensions(File.dirname(__FILE__) + "/data/shipsail.jpg").should eql([192,128])
18
+ @pdf.image_dimensions(File.dirname(__FILE__) + "/data/google.png").should eql([166,55])
19
+ @pdf.image_dimensions(File.dirname(__FILE__) + "/data/zits.gif").should eql([525,167])
20
+ @pdf.image_dimensions(File.dirname(__FILE__) + "/data/orc.svg").should eql([734, 772])
21
+ @pdf.image_dimensions(File.dirname(__FILE__) + "/data/utf8-long.pdf").map{ |d| d.to_i}.should eql([595,841])
22
+ @pdf.image_dimensions(File.dirname(__FILE__) + "/data/shipsail.jpg").should eql([192,128])
22
23
  end
23
24
 
24
25
  specify "should be able to calculate scaled image dimensions correctly" do
25
- pdf = PDF::Wrapper.new
26
- pdf.calc_image_dimensions(100, 100, 200, 200).should eql([100.0,100.0])
27
- pdf.calc_image_dimensions(nil, nil, 200, 200).should eql([200.0,200.0])
28
- pdf.calc_image_dimensions(150, 200, 200, 200, true).should eql([150.0,150.0])
29
- pdf.calc_image_dimensions(300, 250, 200, 200, true).should eql([250.0,250.0])
26
+ @pdf.calc_image_dimensions(100, 100, 200, 200).should eql([100.0,100.0])
27
+ @pdf.calc_image_dimensions(nil, nil, 200, 200).should eql([200.0,200.0])
28
+ @pdf.calc_image_dimensions(150, 200, 200, 200, true).should eql([150.0,150.0])
29
+ @pdf.calc_image_dimensions(300, 250, 200, 200, true).should eql([250.0,250.0])
30
30
  end
31
31
 
32
32
  specify "should be able to draw rotated images correctly" do
33
- pdf = PDF::Wrapper.new
34
- pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :clockwise)
35
- pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :counterclockwise)
36
- pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :upsidedown)
37
- pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :none)
33
+ @pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :clockwise)
34
+ @pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :counterclockwise)
35
+ @pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :upsidedown)
36
+ @pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :none)
38
37
  end
39
38
 
40
39
  specify "should be able to draw an image with padding correctly"
data/specs/load_spec.rb CHANGED
@@ -3,28 +3,29 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  context "The PDF::Wrapper class" do
6
- specify "should load external libs correctly" do
7
- pdf = PDF::Wrapper.new
8
6
 
7
+ before(:each) { create_pdf }
8
+
9
+ specify "should load external libs correctly" do
9
10
  # lib gdkpixbuf
10
11
  ::Object.const_defined?(:Gdk).should eql(false)
11
- pdf.load_libpixbuf
12
+ @pdf.load_libpixbuf
12
13
  ::Object.const_defined?(:Gdk).should eql(true)
13
14
  ::Gdk.const_defined?(:Pixbuf).should eql(true)
14
15
 
15
16
  # pango
16
17
  ::Object.const_defined?(:Pango).should eql(false)
17
- pdf.load_libpango
18
+ @pdf.load_libpango
18
19
  ::Object.const_defined?(:Pango).should eql(true)
19
20
 
20
21
  # libpoppler
21
22
  ::Object.const_defined?(:Poppler).should eql(false)
22
- pdf.load_libpoppler
23
+ @pdf.load_libpoppler
23
24
  ::Object.const_defined?(:Poppler).should eql(true)
24
25
 
25
26
  # librsvg
26
27
  ::Object.const_defined?(:RSVG).should eql(false)
27
- pdf.load_librsvg
28
+ @pdf.load_librsvg
28
29
  ::Object.const_defined?(:RSVG).should eql(true)
29
30
 
30
31
  end
data/specs/spec_helper.rb CHANGED
@@ -10,6 +10,11 @@ gem "pdf-reader", ">=0.7.3"
10
10
 
11
11
  require 'pdf/reader'
12
12
 
13
+ def create_pdf
14
+ @output = StringIO.new
15
+ @pdf = PDF::Wrapper.new(@output, :paper => :A4)
16
+ end
17
+
13
18
  # make some private methods of PDF::Wrapper public for testing
14
19
  class PDF::Wrapper
15
20
  public :build_pango_layout
data/specs/tables_spec.rb CHANGED
@@ -3,13 +3,16 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  context "The PDF::Wrapper class" do
6
+
7
+ before(:each) { create_pdf }
8
+
6
9
  specify "should be able to draw a table on the canvas using an array of data" do
7
- pdf = PDF::Wrapper.new
8
10
  data = [%w{data1 data2}, %w{data3 data4}]
9
- pdf.table(data)
11
+ @pdf.table(data)
12
+ @pdf.finish
10
13
 
11
14
  receiver = PageTextReceiver.new
12
- reader = PDF::Reader.string(pdf.render, receiver)
15
+ reader = PDF::Reader.string(@output.string, receiver)
13
16
 
14
17
  receiver.content.first.include?("data1").should be_true
15
18
  receiver.content.first.include?("data2").should be_true
@@ -18,15 +21,15 @@ context "The PDF::Wrapper class" do
18
21
  end
19
22
 
20
23
  specify "should be able to draw a table on the canvas using a PDF::Wrapper::Table object" do
21
- pdf = PDF::Wrapper.new
22
24
  table = PDF::Wrapper::Table.new do |t|
23
25
  t.data = [%w{data1 data2}, %w{data3 data4}]
24
26
  end
25
27
 
26
- pdf.table(table)
28
+ @pdf.table(table)
29
+ @pdf.finish
27
30
 
28
31
  receiver = PageTextReceiver.new
29
- reader = PDF::Reader.string(pdf.render, receiver)
32
+ reader = PDF::Reader.string(@output.string, receiver)
30
33
 
31
34
  receiver.content.first.include?("data1").should be_true
32
35
  receiver.content.first.include?("data2").should be_true
@@ -35,36 +38,36 @@ context "The PDF::Wrapper class" do
35
38
  end
36
39
 
37
40
  specify "should be able to draw a table on the canvas with no headings" do
38
- pdf = PDF::Wrapper.new
39
41
 
40
42
  table = PDF::Wrapper::Table.new do |t|
41
43
  t.data = (1..50).collect { [1,2] }
42
- t.headers = ["col1", "col2"]
44
+ t.headers ["col1", "col2"]
43
45
  t.show_headers = nil
44
46
  end
45
47
 
46
- pdf.table(table)
48
+ @pdf.table(table)
49
+ @pdf.finish
47
50
 
48
51
  receiver = PageTextReceiver.new
49
- reader = PDF::Reader.string(pdf.render, receiver)
52
+ reader = PDF::Reader.string(@output.string, receiver)
50
53
 
51
54
  receiver.content.first.include?("col1").should be_false
52
55
  receiver.content.first.include?("col2").should be_false
53
56
  end
54
57
 
55
58
  specify "should be able to draw a table on the canvas with headers on the first page only" do
56
- pdf = PDF::Wrapper.new
57
59
 
58
60
  table = PDF::Wrapper::Table.new do |t|
59
61
  t.data = (1..50).collect { [1,2] }
60
- t.headers = ["col1", "col2"]
62
+ t.headers ["col1", "col2"]
61
63
  t.show_headers = :once
62
64
  end
63
65
 
64
- pdf.table(table)
66
+ @pdf.table(table)
67
+ @pdf.finish
65
68
 
66
69
  receiver = PageTextReceiver.new
67
- reader = PDF::Reader.string(pdf.render, receiver)
70
+ reader = PDF::Reader.string(@output.string, receiver)
68
71
 
69
72
  receiver.content[0].include?("col1").should be_true
70
73
  receiver.content[0].include?("col2").should be_true
@@ -73,18 +76,18 @@ context "The PDF::Wrapper class" do
73
76
  end
74
77
 
75
78
  specify "should be able to draw a table on the canvas with headers on all pages" do
76
- pdf = PDF::Wrapper.new
77
79
 
78
80
  table = PDF::Wrapper::Table.new do |t|
79
81
  t.data = (1..50).collect { [1,2] }
80
- t.headers = ["col1", "col2"]
82
+ t.headers ["col1", "col2"]
81
83
  t.show_headers = :page
82
84
  end
83
85
 
84
- pdf.table(table)
86
+ @pdf.table(table)
87
+ @pdf.finish
85
88
 
86
89
  receiver = PageTextReceiver.new
87
- reader = PDF::Reader.string(pdf.render, receiver)
90
+ reader = PDF::Reader.string(@output.string, receiver)
88
91
 
89
92
  receiver.content[0].include?("col1").should be_true
90
93
  receiver.content[0].include?("col2").should be_true
@@ -93,18 +96,16 @@ context "The PDF::Wrapper class" do
93
96
  end
94
97
 
95
98
  specify "should leave the cursor in the bottom left when adding a table" do
96
- pdf = PDF::Wrapper.new
97
99
  data = [%w{head1 head2},%w{data1 data2}]
98
- pdf.table(data, :left => pdf.margin_left)
99
- x,y = pdf.current_point
100
- x.to_i.should eql(pdf.margin_left)
100
+ @pdf.table(data, :left => @pdf.margin_left)
101
+ x,y = @pdf.current_point
102
+ x.to_i.should eql(@pdf.margin_left)
101
103
  end
102
104
 
103
105
  specify "should default to using as much available space when adding a table that isn't left aligned with the left margin" do
104
- pdf = PDF::Wrapper.new
105
106
  data = [%w{head1 head2},%w{data1 data2}]
106
- pdf.table(data, :left => 100)
107
- x,y = pdf.current_point
107
+ @pdf.table(data, :left => 100)
108
+ x,y = @pdf.current_point
108
109
  x.to_i.should eql(100)
109
110
  end
110
111
 
data/specs/text_spec.rb CHANGED
@@ -3,13 +3,30 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  context "The PDF::Wrapper class" do
6
+
7
+ before(:each) { create_pdf }
8
+
9
+ specify "should be able to permanantly change the font size" do
10
+ @pdf.font_size 20
11
+ @pdf.instance_variable_get("@default_font_size").should eql(20)
12
+ end
13
+
14
+ specify "should be able to temporarily change the font size" do
15
+ @pdf.font_size 20
16
+ @pdf.instance_variable_get("@default_font_size").should eql(20)
17
+ @pdf.font_size(10) do
18
+ @pdf.instance_variable_get("@default_font_size").should eql(10)
19
+ end
20
+ @pdf.instance_variable_get("@default_font_size").should eql(20)
21
+ end
22
+
6
23
  specify "should be able to add ascii text to the canvas" do
7
24
  msg = "Chunky Bacon"
8
- pdf = PDF::Wrapper.new
9
- pdf.text msg
25
+ @pdf.text msg
26
+ @pdf.finish
10
27
 
11
28
  receiver = PageTextReceiver.new
12
- reader = PDF::Reader.string(pdf.render, receiver)
29
+ reader = PDF::Reader.string(@output.string, receiver)
13
30
 
14
31
  # TODO: test for the text is in the appropriate location on the page
15
32
  receiver.content.first.should eql(msg)
@@ -17,11 +34,11 @@ context "The PDF::Wrapper class" do
17
34
 
18
35
  specify "should be able to add unicode text to the canvas" do
19
36
  msg = "Alex Čihař"
20
- pdf = PDF::Wrapper.new
21
- pdf.text msg
37
+ @pdf.text msg
38
+ @pdf.finish
22
39
 
23
40
  receiver = PageTextReceiver.new
24
- reader = PDF::Reader.string(pdf.render, receiver)
41
+ reader = PDF::Reader.string(@output.string, receiver)
25
42
 
26
43
  # TODO: test for the text is in the appropriate location on the page
27
44
  receiver.content.first.should eql(msg)
@@ -29,11 +46,11 @@ context "The PDF::Wrapper class" do
29
46
 
30
47
  specify "should be able to add unicode text that spans multiple pages to the canvas" do
31
48
  msg = "James\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nHealy"
32
- pdf = PDF::Wrapper.new
33
- pdf.text msg
49
+ @pdf.text msg
50
+ @pdf.finish
34
51
 
35
52
  receiver = PageTextReceiver.new
36
- reader = PDF::Reader.string(pdf.render, receiver)
53
+ reader = PDF::Reader.string(@output.string, receiver)
37
54
 
38
55
  receiver.content.size.should eql(2)
39
56
  receiver.content[0].should eql("James")
@@ -42,73 +59,72 @@ context "The PDF::Wrapper class" do
42
59
 
43
60
  specify "should be align text on the left when using the text method" do
44
61
  msg = "Chunky Bacon"
45
- pdf = PDF::Wrapper.new
46
- pdf.text msg, :alignment => :left
62
+ @pdf.text msg, :alignment => :left
63
+ @pdf.finish
47
64
 
48
65
  receiver = PDF::Reader::RegisterReceiver.new
49
- reader = PDF::Reader.string(pdf.render, receiver)
66
+ reader = PDF::Reader.string(@output.string, receiver)
50
67
 
51
68
  # ensure the text is placed in the right location
52
69
  params = receiver.first_occurance_of(:set_text_matrix_and_text_line_matrix)[:args]
53
- params[4].should eql(pdf.margin_left.to_f)
70
+ params[4].should eql(@pdf.margin_left.to_f)
54
71
  end
55
72
 
56
73
  specify "should be able to align text on the left when using the text method" do
57
74
  msg = "Chunky Bacon"
58
- pdf = PDF::Wrapper.new
59
- pdf.text msg, :alignment => :left
75
+ @pdf.text msg, :alignment => :left
76
+ @pdf.finish
60
77
 
61
78
  receiver = PDF::Reader::RegisterReceiver.new
62
- reader = PDF::Reader.string(pdf.render, receiver)
79
+ reader = PDF::Reader.string(@output.string, receiver)
63
80
 
64
81
  # ensure the text is placed in the right location
65
82
  params = receiver.first_occurance_of(:set_text_matrix_and_text_line_matrix)[:args]
66
- params[4].should eql(pdf.margin_left.to_f)
83
+ params[4].should eql(@pdf.margin_left.to_f)
67
84
  end
68
85
 
69
86
  specify "should be able to align text in the centre when using the text method" do
70
87
  msg = "Chunky Bacon"
71
- pdf = PDF::Wrapper.new
72
- pdf.text msg, :alignment => :center
88
+ @pdf.text msg, :alignment => :center
89
+ @pdf.finish
73
90
 
74
91
  receiver = PDF::Reader::RegisterReceiver.new
75
- reader = PDF::Reader.string(pdf.render, receiver)
92
+ reader = PDF::Reader.string(@output.string, receiver)
76
93
 
77
94
  # ensure the text is placed in the right location - the left
78
95
  # egde should be less than half way across the page, but not on the left margin
79
96
  params = receiver.first_occurance_of(:set_text_matrix_and_text_line_matrix)[:args]
80
- (params[4] < pdf.absolute_x_middle).should be_true
81
- (params[4] > pdf.absolute_x_middle - 100).should be_true
97
+ (params[4] < @pdf.absolute_x_middle).should be_true
98
+ (params[4] > @pdf.absolute_x_middle - 100).should be_true
82
99
  end
83
100
 
84
101
  specify "should be able to align text on the right when using the text method" do
85
102
  msg = "Chunky Bacon"
86
- pdf = PDF::Wrapper.new
87
- pdf.text msg, :alignment => :right
103
+ @pdf.text msg, :alignment => :right
104
+ @pdf.finish
88
105
 
89
106
  receiver = PDF::Reader::RegisterReceiver.new
90
- reader = PDF::Reader.string(pdf.render, receiver)
107
+ reader = PDF::Reader.string(@output.string, receiver)
91
108
 
92
109
  # ensure the text is placed in the right location - the left
93
110
  # egde should be more than half way across the page, but not on the right margin
94
111
  params = receiver.first_occurance_of(:set_text_matrix_and_text_line_matrix)[:args]
95
- (params[4] > pdf.absolute_x_middle).should be_true
96
- (params[4] < pdf.absolute_right_margin).should be_true
112
+ (params[4] > @pdf.absolute_x_middle).should be_true
113
+ (params[4] < @pdf.absolute_right_margin).should be_true
97
114
  end
98
115
 
99
116
  specify "should raise an error when an invalid alignment is specified" do
100
117
  msg = "James Healy"
101
- pdf = PDF::Wrapper.new
102
- lambda { pdf.text msg, :alignment => :ponies }.should raise_error(ArgumentError)
118
+ lambda { @pdf.text msg, :alignment => :ponies }.should raise_error(ArgumentError)
103
119
  end
104
120
 
105
121
  specify "should be able to add text to the canvas in a bounding box using the cell method" do
106
122
  msg = "Alex Čihař"
107
- pdf = PDF::Wrapper.new
108
- pdf.cell msg, 100, 100, 200, 200
123
+ @pdf.cell msg, 100, 100, 200, 200
124
+ @pdf.finish
109
125
 
110
126
  receiver = PageTextReceiver.new
111
- reader = PDF::Reader.string(pdf.render, receiver)
127
+ reader = PDF::Reader.string(@output.string, receiver)
112
128
 
113
129
  # TODO: test for the text is in the appropriate location on the page
114
130
  receiver.content.first.should eql(msg)
@@ -116,13 +132,13 @@ context "The PDF::Wrapper class" do
116
132
 
117
133
  specify "should keep all text for a cell inside the cell boundaries" do
118
134
  msg = "This is a text cell, added by James"
119
- pdf = PDF::Wrapper.new
120
135
  x = y = 100
121
136
  w = h = 200
122
- pdf.cell msg, x, y, w, h
137
+ @pdf.cell msg, x, y, w, h
138
+ @pdf.finish
123
139
 
124
140
  receiver = PDF::Reader::RegisterReceiver.new
125
- reader = PDF::Reader.string(pdf.render, receiver)
141
+ reader = PDF::Reader.string(@output.string, receiver)
126
142
 
127
143
  receiver.all(:set_text_matrix_and_text_line_matrix).each do |cb|
128
144
  # horizontal location
@@ -134,7 +150,7 @@ context "The PDF::Wrapper class" do
134
150
  # vertical location
135
151
  # TODO: we're only testing the it doesn't start past the bottom boundary of the cell
136
152
  # should also test that it doesn't start in the cell but overrun it
137
- cell_top_bound = pdf.page_height - y
153
+ cell_top_bound = @pdf.page_height - y
138
154
  (cb[:args][5] <= cell_top_bound).should be_true
139
155
  (cb[:args][5] >= cell_top_bound - h).should be_true
140
156
  end
@@ -142,37 +158,33 @@ context "The PDF::Wrapper class" do
142
158
 
143
159
  specify "should be able to calculate the height of a string of text" do
144
160
  str = "This is a medium length string\nthat is also multi line. one two three four."
145
- pdf = PDF::Wrapper.new
146
161
  opts = {:font_size => 16, :font => "Sans Serif", :alignment => :left, :justify => false }
147
- pdf.text_height(str, pdf.body_width, opts).should eql(49)
162
+ @pdf.text_height(str, @pdf.body_width, opts).should eql(49)
148
163
  end
149
164
 
150
165
  specify "should be able to calculate the width of a string of text" do
151
166
  str = "James Healy"
152
167
  str2 = "James Healy is a Ruby dev that lives in Melbourne, Australia. His day job mostly involved Ruby on Rails."
153
- pdf = PDF::Wrapper.new
154
168
  opts = {:font_size => 16, :font => "Sans Serif"}
155
- pdf.text(str, opts)
156
- pdf.text_width(str, opts).should eql(131)
157
- pdf.text_width(str2, opts).should eql(1107)
169
+ @pdf.text(str, opts)
170
+ @pdf.text_width(str, opts).should eql(131)
171
+ @pdf.text_width(str2, opts).should eql(1107)
158
172
  end
159
173
 
160
174
  specify "should raise an exception if build_pango_layout is passed anything other than a string" do
161
- pdf = PDF::Wrapper.new
162
- lambda { pdf.build_pango_layout(10) }.should raise_error(ArgumentError)
175
+ lambda { @pdf.build_pango_layout(10) }.should raise_error(ArgumentError)
163
176
  end
164
177
 
165
178
  if RUBY_VERSION >= "1.9"
166
179
  specify "should accept non UTF-8 strings to build_pango_layout and convert them on the fly" do
167
- pdf = PDF::Wrapper.new
168
180
 
169
181
  # all three of these files have the same content, but in different encodings
170
182
  iso2022_str = File.open(File.dirname(__FILE__) + "/data/shift_jis.txt", "r:ISO-2022-JP") { |f| f.read }.strip!
171
183
  shiftjis_str = File.open(File.dirname(__FILE__) + "/data/iso-2022-jp.txt", "r:Shift_JIS") { |f| f.read }.strip!
172
184
  utf8_str = File.open(File.dirname(__FILE__) + "/data/utf8.txt", "r:UTF-8") { |f| f.read }.strip!
173
185
 
174
- pdf.build_pango_layout(shiftjis_str)
175
- pdf.build_pango_layout(iso2022_str)
186
+ @pdf.build_pango_layout(shiftjis_str)
187
+ @pdf.build_pango_layout(iso2022_str)
176
188
 
177
189
  # TODO: improve this spec using mocks. Atm, I'm assume that if build_pango_layout didn't raise an exception when
178
190
  # passed in the non UTF-8 strings, then all worked fine. yuck.
@@ -183,11 +195,11 @@ context "The PDF::Wrapper class" do
183
195
 
184
196
  specify "should accept and render pango markup correctly" do
185
197
  msg = "<b>James</b>"
186
- pdf = PDF::Wrapper.new
187
- pdf.text msg, :markup => :pango
198
+ @pdf.text msg, :markup => :pango
199
+ @pdf.finish
188
200
 
189
201
  receiver = PageTextReceiver.new
190
- reader = PDF::Reader.string(pdf.render, receiver)
202
+ reader = PDF::Reader.string(@output.string, receiver)
191
203
 
192
204
  page_one = receiver.content.first.dup
193
205
  page_one.should eql("James")
@@ -195,11 +207,11 @@ context "The PDF::Wrapper class" do
195
207
 
196
208
  specify "should be able to alle to wrap text on word boundaries" do
197
209
  msg = "James Healy"
198
- pdf = PDF::Wrapper.new
199
- pdf.text msg, :wrap => :word
210
+ @pdf.text msg, :wrap => :word
211
+ @pdf.finish
200
212
 
201
213
  receiver = PageTextReceiver.new
202
- reader = PDF::Reader.string(pdf.render, receiver)
214
+ reader = PDF::Reader.string(@output.string, receiver)
203
215
 
204
216
  # TODO: test for the text is in the appropriate location on the page
205
217
  receiver.content.first.should eql(msg)
@@ -207,11 +219,11 @@ context "The PDF::Wrapper class" do
207
219
 
208
220
  specify "should be able to able to wrap text on char boundaries" do
209
221
  msg = "James Healy"
210
- pdf = PDF::Wrapper.new
211
- pdf.text msg, :wrap => :char
222
+ @pdf.text msg, :wrap => :char
223
+ @pdf.finish
212
224
 
213
225
  receiver = PageTextReceiver.new
214
- reader = PDF::Reader.string(pdf.render, receiver)
226
+ reader = PDF::Reader.string(@output.string, receiver)
215
227
 
216
228
  # TODO: test for the text is in the appropriate location on the page
217
229
  receiver.content.first.should eql(msg)
@@ -219,11 +231,11 @@ context "The PDF::Wrapper class" do
219
231
 
220
232
  specify "should be able to wrap text on word and char boundaries" do
221
233
  msg = "James Healy"
222
- pdf = PDF::Wrapper.new
223
- pdf.text msg, :wrap => :wordchar
234
+ @pdf.text msg, :wrap => :wordchar
235
+ @pdf.finish
224
236
 
225
237
  receiver = PageTextReceiver.new
226
- reader = PDF::Reader.string(pdf.render, receiver)
238
+ reader = PDF::Reader.string(@output.string, receiver)
227
239
 
228
240
  # TODO: test for the text is in the appropriate location on the page
229
241
  receiver.content.first.should eql(msg)
@@ -231,8 +243,7 @@ context "The PDF::Wrapper class" do
231
243
 
232
244
  specify "should raise an error when an invalid wrapping technique is specified" do
233
245
  msg = "James Healy"
234
- pdf = PDF::Wrapper.new
235
- lambda { pdf.text msg, :wrap => :ponies }.should raise_error(ArgumentError)
246
+ lambda { @pdf.text msg, :wrap => :ponies }.should raise_error(ArgumentError)
236
247
  end
237
248
 
238
249
  end