prawn 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -5
  3. data/lib/prawn.rb +4 -4
  4. data/lib/prawn/document.rb +47 -46
  5. data/lib/prawn/document/bounding_box.rb +13 -19
  6. data/lib/prawn/document/column_box.rb +3 -5
  7. data/lib/prawn/document/internals.rb +0 -1
  8. data/lib/prawn/document/span.rb +12 -12
  9. data/lib/prawn/errors.rb +32 -33
  10. data/lib/prawn/font.rb +29 -36
  11. data/lib/prawn/font/afm.rb +20 -20
  12. data/lib/prawn/font/dfont.rb +0 -1
  13. data/lib/prawn/font/ttf.rb +30 -27
  14. data/lib/prawn/font_metric_cache.rb +4 -8
  15. data/lib/prawn/graphics.rb +37 -42
  16. data/lib/prawn/graphics/cap_style.rb +1 -1
  17. data/lib/prawn/graphics/color.rb +21 -23
  18. data/lib/prawn/graphics/dash.rb +5 -6
  19. data/lib/prawn/graphics/join_style.rb +1 -2
  20. data/lib/prawn/graphics/patterns.rb +25 -21
  21. data/lib/prawn/graphics/transformation.rb +4 -5
  22. data/lib/prawn/graphics/transparency.rb +6 -8
  23. data/lib/prawn/grid.rb +21 -14
  24. data/lib/prawn/image_handler.rb +2 -2
  25. data/lib/prawn/images.rb +29 -31
  26. data/lib/prawn/images/image.rb +1 -1
  27. data/lib/prawn/images/jpg.rb +10 -12
  28. data/lib/prawn/images/png.rb +13 -13
  29. data/lib/prawn/measurements.rb +7 -14
  30. data/lib/prawn/outline.rb +6 -6
  31. data/lib/prawn/repeater.rb +1 -5
  32. data/lib/prawn/security.rb +17 -25
  33. data/lib/prawn/security/arcfour.rb +1 -1
  34. data/lib/prawn/soft_mask.rb +11 -12
  35. data/lib/prawn/stamp.rb +16 -8
  36. data/lib/prawn/text.rb +23 -20
  37. data/lib/prawn/text/box.rb +3 -6
  38. data/lib/prawn/text/formatted/arranger.rb +9 -12
  39. data/lib/prawn/text/formatted/box.rb +23 -22
  40. data/lib/prawn/text/formatted/fragment.rb +0 -4
  41. data/lib/prawn/text/formatted/line_wrap.rb +13 -24
  42. data/lib/prawn/text/formatted/parser.rb +16 -20
  43. data/lib/prawn/text/formatted/wrap.rb +2 -7
  44. data/lib/prawn/utilities.rb +6 -3
  45. data/lib/prawn/version.rb +1 -1
  46. data/manual/basic_concepts/basic_concepts.rb +0 -2
  47. data/manual/basic_concepts/view.rb +1 -1
  48. data/manual/bounding_box/bounding_box.rb +0 -3
  49. data/manual/bounding_box/russian_boxes.rb +7 -8
  50. data/manual/bounding_box/stretchy.rb +0 -1
  51. data/manual/contents.rb +2 -2
  52. data/manual/cover.rb +11 -12
  53. data/manual/document_and_page_options/document_and_page_options.rb +2 -5
  54. data/manual/document_and_page_options/metadata.rb +10 -10
  55. data/manual/document_and_page_options/page_size.rb +0 -1
  56. data/manual/graphics/fill_rules.rb +5 -4
  57. data/manual/graphics/graphics.rb +0 -3
  58. data/manual/graphics/lines_and_curves.rb +1 -1
  59. data/manual/graphics/rotate.rb +0 -2
  60. data/manual/graphics/scale.rb +4 -2
  61. data/manual/graphics/soft_masks.rb +0 -1
  62. data/manual/graphics/stroke_cap.rb +1 -1
  63. data/manual/graphics/stroke_join.rb +1 -1
  64. data/manual/graphics/translate.rb +3 -3
  65. data/manual/graphics/transparency.rb +0 -1
  66. data/manual/how_to_read_this_manual.rb +0 -1
  67. data/manual/images/images.rb +0 -3
  68. data/manual/layout/boxes.rb +5 -5
  69. data/manual/layout/content.rb +2 -2
  70. data/manual/layout/layout.rb +0 -3
  71. data/manual/outline/outline.rb +0 -3
  72. data/manual/repeatable_content/page_numbering.rb +1 -1
  73. data/manual/repeatable_content/repeatable_content.rb +0 -3
  74. data/manual/repeatable_content/repeater.rb +6 -6
  75. data/manual/security/encryption.rb +0 -2
  76. data/manual/security/permissions.rb +0 -2
  77. data/manual/security/security.rb +0 -3
  78. data/manual/text/alignment.rb +3 -3
  79. data/manual/text/color.rb +0 -1
  80. data/manual/text/column_box.rb +0 -1
  81. data/manual/text/fallback_fonts.rb +2 -2
  82. data/manual/text/formatted_callbacks.rb +3 -2
  83. data/manual/text/paragraph_indentation.rb +2 -3
  84. data/manual/text/registering_families.rb +13 -9
  85. data/manual/text/rotation.rb +0 -1
  86. data/manual/text/text.rb +0 -3
  87. data/manual/text/text_box_overflow.rb +7 -5
  88. data/manual/text/utf8.rb +1 -1
  89. data/manual/text/win_ansi_charset.rb +2 -2
  90. data/prawn.gemspec +4 -4
  91. data/spec/acceptance/png.rb +6 -7
  92. data/spec/annotations_spec.rb +21 -28
  93. data/spec/bounding_box_spec.rb +100 -109
  94. data/spec/column_box_spec.rb +26 -32
  95. data/spec/destinations_spec.rb +2 -4
  96. data/spec/document_spec.rb +145 -151
  97. data/spec/extensions/mocha.rb +0 -1
  98. data/spec/font_metric_cache_spec.rb +7 -7
  99. data/spec/font_spec.rb +103 -102
  100. data/spec/formatted_text_arranger_spec.rb +76 -74
  101. data/spec/formatted_text_box_spec.rb +170 -159
  102. data/spec/formatted_text_fragment_spec.rb +57 -56
  103. data/spec/graphics_spec.rb +158 -175
  104. data/spec/grid_spec.rb +28 -29
  105. data/spec/image_handler_spec.rb +4 -5
  106. data/spec/images_spec.rb +50 -36
  107. data/spec/inline_formatted_text_parser_spec.rb +397 -393
  108. data/spec/jpg_spec.rb +4 -6
  109. data/spec/line_wrap_spec.rb +54 -55
  110. data/spec/measurement_units_spec.rb +12 -15
  111. data/spec/outline_spec.rb +77 -98
  112. data/spec/png_spec.rb +55 -65
  113. data/spec/reference_spec.rb +3 -3
  114. data/spec/repeater_spec.rb +20 -26
  115. data/spec/security_spec.rb +42 -49
  116. data/spec/soft_mask_spec.rb +4 -5
  117. data/spec/span_spec.rb +5 -6
  118. data/spec/spec_helper.rb +2 -4
  119. data/spec/stamp_spec.rb +41 -22
  120. data/spec/stroke_styles_spec.rb +36 -39
  121. data/spec/text_at_spec.rb +28 -29
  122. data/spec/text_box_spec.rb +160 -165
  123. data/spec/text_rendering_mode_spec.rb +9 -9
  124. data/spec/text_spacing_spec.rb +13 -13
  125. data/spec/text_spec.rb +116 -124
  126. data/spec/text_with_inline_formatting_spec.rb +5 -5
  127. data/spec/transparency_spec.rb +20 -20
  128. data/spec/view_spec.rb +0 -1
  129. metadata +7 -7
@@ -7,7 +7,6 @@
7
7
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
8
8
 
9
9
  describe "When reading a JPEG file" do
10
-
11
10
  before(:each) do
12
11
  @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
13
12
  @img_data = File.open(@filename, "rb") { |f| f.read }
@@ -16,10 +15,9 @@ describe "When reading a JPEG file" do
16
15
  it "should read the basic attributes correctly" do
17
16
  jpg = Prawn::Images::JPG.new(@img_data)
18
17
 
19
- jpg.width.should == 604
20
- jpg.height.should == 453
21
- jpg.bits.should == 8
22
- jpg.channels.should == 3
18
+ expect(jpg.width).to eq(604)
19
+ expect(jpg.height).to eq(453)
20
+ expect(jpg.bits).to eq(8)
21
+ expect(jpg.channels).to eq(3)
23
22
  end
24
23
  end
25
-
@@ -14,31 +14,31 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
14
14
  { :text => "goodbye ", :style => [:bold] }]
15
15
  @arranger.format_array = array
16
16
  string = @line_wrap.wrap_line(:arranger => @arranger,
17
- :width => 300,
18
- :document => @pdf)
19
- string.should == "hello world, goodbye"
17
+ :width => 300,
18
+ :document => @pdf)
19
+ expect(string).to eq("hello world, goodbye")
20
20
  end
21
- it "should strip trailing spaces when a white-space-only fragment was" +
22
- " successfully pushed onto the end of a line but no other non-white" +
21
+ it "should strip trailing spaces when a white-space-only fragment was" \
22
+ " successfully pushed onto the end of a line but no other non-white" \
23
23
  " space fragment fits after it" do
24
24
  array = [{ :text => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " },
25
25
  { :text => " ", :style => [:bold] },
26
26
  { :text => " bbbbbbbbbbbbbbbbbbbbbbbbbbbb" }]
27
27
  @arranger.format_array = array
28
28
  string = @line_wrap.wrap_line(:arranger => @arranger,
29
- :width => 300,
30
- :document => @pdf)
31
- string.should == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
29
+ :width => 300,
30
+ :document => @pdf)
31
+ expect(string).to eq("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
32
32
  end
33
33
  it "should raise_error CannotFit if a too-small width is given" do
34
34
  array = [{ :text => " hello world, " },
35
35
  { :text => "goodbye ", :style => [:bold] }]
36
36
  @arranger.format_array = array
37
- lambda do
37
+ expect do
38
38
  @line_wrap.wrap_line(:arranger => @arranger,
39
39
  :width => 1,
40
40
  :document => @pdf)
41
- end.should raise_error(Prawn::Errors::CannotFit)
41
+ end.to raise_error(Prawn::Errors::CannotFit)
42
42
  end
43
43
 
44
44
  it "should break on space" do
@@ -47,7 +47,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
47
47
  string = @line_wrap.wrap_line(:arranger => @arranger,
48
48
  :width => @one_word_width,
49
49
  :document => @pdf)
50
- string.should == "hello"
50
+ expect(string).to eq("hello")
51
51
  end
52
52
 
53
53
  it "should break on zero-width space" do
@@ -57,7 +57,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
57
57
  string = @line_wrap.wrap_line(:arranger => @arranger,
58
58
  :width => @one_word_width,
59
59
  :document => @pdf)
60
- string.should == "hello"
60
+ expect(string).to eq("hello")
61
61
  end
62
62
 
63
63
  it "should not display zero-width space" do
@@ -67,7 +67,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
67
67
  string = @line_wrap.wrap_line(:arranger => @arranger,
68
68
  :width => 300,
69
69
  :document => @pdf)
70
- string.should == "helloworld"
70
+ expect(string).to eq("helloworld")
71
71
  end
72
72
 
73
73
  it "should break on tab" do
@@ -76,7 +76,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
76
76
  string = @line_wrap.wrap_line(:arranger => @arranger,
77
77
  :width => @one_word_width,
78
78
  :document => @pdf)
79
- string.should == "hello"
79
+ expect(string).to eq("hello")
80
80
  end
81
81
 
82
82
  it "should break on hyphens" do
@@ -85,24 +85,24 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
85
85
  string = @line_wrap.wrap_line(:arranger => @arranger,
86
86
  :width => @one_word_width,
87
87
  :document => @pdf)
88
- string.should == "hello-"
88
+ expect(string).to eq("hello-")
89
89
  end
90
90
 
91
- it "should not break after a hyphen that follows white space and" +
91
+ it "should not break after a hyphen that follows white space and" \
92
92
  "precedes a word" do
93
93
  array = [{ :text => "hello -" }]
94
94
  @arranger.format_array = array
95
95
  string = @line_wrap.wrap_line(:arranger => @arranger,
96
96
  :width => @one_word_width,
97
97
  :document => @pdf)
98
- string.should == "hello -"
98
+ expect(string).to eq("hello -")
99
99
 
100
100
  array = [{ :text => "hello -world" }]
101
101
  @arranger.format_array = array
102
102
  string = @line_wrap.wrap_line(:arranger => @arranger,
103
103
  :width => @one_word_width,
104
104
  :document => @pdf)
105
- string.should == "hello"
105
+ expect(string).to eq("hello")
106
106
  end
107
107
 
108
108
  it "should break on a soft hyphen" do
@@ -114,7 +114,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
114
114
  :document => @pdf)
115
115
  expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
116
116
  expected.force_encoding(Encoding::UTF_8)
117
- string.should == expected
117
+ expect(string).to eq(expected)
118
118
 
119
119
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
120
120
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
@@ -125,16 +125,16 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
125
125
  string = @line_wrap.wrap_line(:arranger => @arranger,
126
126
  :width => @one_word_width,
127
127
  :document => @pdf)
128
- string.should == "hello#{Prawn::Text::SHY}"
128
+ expect(string).to eq("hello#{Prawn::Text::SHY}")
129
129
  end
130
130
 
131
- it "should ignore width of a soft-hyphen during adding fragments to line", :issue =>775 do
131
+ it "should ignore width of a soft-hyphen during adding fragments to line", :issue => 775 do
132
132
  hyphen_string = "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}nat#{Prawn::Text::SHY}ions "
133
133
  string1 = @pdf.font.normalize_encoding(hyphen_string * 5)
134
134
  string2 = @pdf.font.normalize_encoding("Hyphenations " * 3 + hyphen_string)
135
135
 
136
- array1 = [{text: string1}]
137
- array2 = [{text: string2}]
136
+ array1 = [{ text: string1 }]
137
+ array2 = [{ text: string2 }]
138
138
 
139
139
  @arranger.format_array = array1
140
140
 
@@ -149,10 +149,10 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
149
149
  res2 = @line_wrap.wrap_line(:arranger => @arranger,
150
150
  :width => 300,
151
151
  :document => @pdf)
152
- res1.should == res2
152
+ expect(res1).to eq(res2)
153
153
  end
154
154
 
155
- it "should not display soft hyphens except at the end of a line " +
155
+ it "should not display soft hyphens except at the end of a line " \
156
156
  "for more than one element in format_array", :issue => 347 do
157
157
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
158
158
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
@@ -164,7 +164,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
164
164
  string = @line_wrap.wrap_line(:arranger => @arranger,
165
165
  :width => 300,
166
166
  :document => @pdf)
167
- string.should == "helloworld hiearth"
167
+ expect(string).to eq("helloworld hiearth")
168
168
  end
169
169
 
170
170
  it "should not break before a hard hyphen that follows a word" do
@@ -175,14 +175,14 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
175
175
  string = @line_wrap.wrap_line(:arranger => @arranger,
176
176
  :width => enough_width_for_hello_world,
177
177
  :document => @pdf)
178
- string.should == "hello world"
178
+ expect(string).to eq("hello world")
179
179
 
180
180
  array = [{ :text => "hello world-" }]
181
181
  @arranger.format_array = array
182
182
  string = @line_wrap.wrap_line(:arranger => @arranger,
183
183
  :width => enough_width_for_hello_world,
184
184
  :document => @pdf)
185
- string.should == "hello"
185
+ expect(string).to eq("hello")
186
186
 
187
187
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
188
188
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
@@ -193,17 +193,17 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
193
193
  string = @line_wrap.wrap_line(:arranger => @arranger,
194
194
  :width => enough_width_for_hello_world,
195
195
  :document => @pdf)
196
- string.should == "hello world"
196
+ expect(string).to eq("hello world")
197
197
 
198
198
  array = [{ :text => "hello world-" }]
199
199
  @arranger.format_array = array
200
200
  string = @line_wrap.wrap_line(:arranger => @arranger,
201
201
  :width => enough_width_for_hello_world,
202
202
  :document => @pdf)
203
- string.should == "hello"
203
+ expect(string).to eq("hello")
204
204
  end
205
205
 
206
- it "should not break after a hard hyphen that follows a soft hyphen and" +
206
+ it "should not break after a hard hyphen that follows a soft hyphen and" \
207
207
  "precedes a word" do
208
208
  string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-")
209
209
  array = [{ :text => string }]
@@ -211,7 +211,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
211
211
  string = @line_wrap.wrap_line(:arranger => @arranger,
212
212
  :width => @one_word_width,
213
213
  :document => @pdf)
214
- string.should == "hello-"
214
+ expect(string).to eq("hello-")
215
215
 
216
216
  string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-world")
217
217
  array = [{ :text => string }]
@@ -221,7 +221,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
221
221
  :document => @pdf)
222
222
  expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
223
223
  expected.force_encoding(Encoding::UTF_8)
224
- string.should == expected
224
+ expect(string).to eq(expected)
225
225
 
226
226
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
227
227
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
@@ -232,7 +232,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
232
232
  string = @line_wrap.wrap_line(:arranger => @arranger,
233
233
  :width => @one_word_width,
234
234
  :document => @pdf)
235
- string.should == "hello-"
235
+ expect(string).to eq("hello-")
236
236
 
237
237
  string = "hello#{Prawn::Text::SHY}-world"
238
238
  array = [{ :text => string }]
@@ -240,7 +240,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
240
240
  string = @line_wrap.wrap_line(:arranger => @arranger,
241
241
  :width => @one_word_width,
242
242
  :document => @pdf)
243
- string.should == "hello#{Prawn::Text::SHY}"
243
+ expect(string).to eq("hello#{Prawn::Text::SHY}")
244
244
  end
245
245
 
246
246
  it "should process UTF-8 chars", :unresolved, :issue => 693 do
@@ -251,7 +251,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
251
251
  string = @line_wrap.wrap_line(:arranger => @arranger,
252
252
  :width => 300,
253
253
  :document => @pdf)
254
- string.should == "Test"
254
+ expect(string).to eq("Test")
255
255
  end
256
256
  end
257
257
 
@@ -266,18 +266,18 @@ describe "Core::Text::Formatted::LineWrap#space_count" do
266
266
  { :text => "goodbye", :style => [:bold] }]
267
267
  @arranger.format_array = array
268
268
  @line_wrap.wrap_line(:arranger => @arranger,
269
- :width => 300,
270
- :document => @pdf)
271
- @line_wrap.space_count.should == 2
269
+ :width => 300,
270
+ :document => @pdf)
271
+ expect(@line_wrap.space_count).to eq(2)
272
272
  end
273
273
  it "should exclude preceding and trailing spaces from the count" do
274
274
  array = [{ :text => " hello world, " },
275
275
  { :text => "goodbye ", :style => [:bold] }]
276
276
  @arranger.format_array = array
277
277
  @line_wrap.wrap_line(:arranger => @arranger,
278
- :width => 300,
279
- :document => @pdf)
280
- @line_wrap.space_count.should == 2
278
+ :width => 300,
279
+ :document => @pdf)
280
+ expect(@line_wrap.space_count).to eq(2)
281
281
  end
282
282
  end
283
283
 
@@ -296,22 +296,22 @@ describe "Core::Text::Formatted::LineWrap" do
296
296
  @arranger.format_array = array
297
297
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
298
298
  end
299
- it "should only return an empty string if nothing fit or there" +
299
+ it "should only return an empty string if nothing fit or there" \
300
300
  "was nothing to wrap" do
301
301
  8.times do
302
302
  line = @line_wrap.wrap_line(:arranger => @arranger,
303
- :width => 200,
304
- :document => @pdf)
305
- line.should_not be_empty
303
+ :width => 200,
304
+ :document => @pdf)
305
+ expect(line).not_to be_empty
306
306
  end
307
307
  line = @line_wrap.wrap_line(:arranger => @arranger,
308
- :width => 200,
309
- :document => @pdf)
310
- line.should be_empty
308
+ :width => 200,
309
+ :document => @pdf)
310
+ expect(line).to be_empty
311
311
  end
312
312
  it "should tokenize a string using the scan_pattern" do
313
313
  tokens = @line_wrap.tokenize("one two three")
314
- tokens.length.should == 6
314
+ expect(tokens.length).to eq(6)
315
315
  end
316
316
  end
317
317
 
@@ -329,7 +329,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
329
329
  :width => @one_word_width,
330
330
  :document => @pdf)
331
331
 
332
- @line_wrap.paragraph_finished?.should == false
332
+ expect(@line_wrap.paragraph_finished?).to eq(false)
333
333
  end
334
334
  it "should be_true when the last printed line is the last fragment to print" do
335
335
  array = [{ :text => "hello world" }]
@@ -341,7 +341,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
341
341
  :width => @one_word_width,
342
342
  :document => @pdf)
343
343
 
344
- @line_wrap.paragraph_finished?.should == true
344
+ expect(@line_wrap.paragraph_finished?).to eq(true)
345
345
  end
346
346
  it "should be_true when a newline exists on the current line" do
347
347
  array = [{ :text => "hello\n world" }]
@@ -350,7 +350,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
350
350
  :width => @one_word_width,
351
351
  :document => @pdf)
352
352
 
353
- @line_wrap.paragraph_finished?.should == true
353
+ expect(@line_wrap.paragraph_finished?).to eq(true)
354
354
  end
355
355
  it "should be_true when a newline exists in the next fragment" do
356
356
  array = [{ :text => "hello " },
@@ -361,7 +361,6 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
361
361
  :width => @one_word_width,
362
362
  :document => @pdf)
363
363
 
364
- @line_wrap.paragraph_finished?.should == true
364
+ expect(@line_wrap.paragraph_finished?).to eq(true)
365
365
  end
366
366
  end
367
-
@@ -4,22 +4,19 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
  require "prawn/measurement_extensions"
5
5
 
6
6
  describe "Measurement units" do
7
-
8
7
  it "should convert units to PostScriptPoints" do
9
- 1.mm.should be_within(0.000000001).of(2.834645669)
10
- 1.mm.should == (72 / 25.4)
11
- 2.mm.should == (2 * 72 / 25.4)
12
- 3.mm.should == 3 * 72 / 25.4
13
- -3.mm.should == -3 * 72/25.4
14
- 1.cm.should == 10 * 72 / 25.4
15
- 1.dm.should == 100 * 72 / 25.4
16
- 1.m.should == 1000 * 72 / 25.4
8
+ expect(1.mm).to be_within(0.000000001).of(2.834645669)
9
+ expect(1.mm).to eq(72 / 25.4)
10
+ expect(2.mm).to eq(2 * 72 / 25.4)
11
+ expect(3.mm).to eq(3 * 72 / 25.4)
12
+ expect(-3.mm).to eq(-3 * 72 / 25.4)
13
+ expect(1.cm).to eq(10 * 72 / 25.4)
14
+ expect(1.dm).to eq(100 * 72 / 25.4)
15
+ expect(1.m).to eq(1000 * 72 / 25.4)
17
16
 
18
- 1.in.should == 72
19
- 1.ft.should == 72 * 12
20
- 1.yd.should == 72 * 12 * 3
21
- 1.pt.should == 1
17
+ expect(1.in).to eq(72)
18
+ expect(1.ft).to eq(72 * 12)
19
+ expect(1.yd).to eq(72 * 12 * 3)
20
+ expect(1.pt).to eq(1)
22
21
  end
23
-
24
22
  end
25
-
@@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
 
4
4
  describe "Outline" do
5
5
  before(:each) do
6
- @pdf = Prawn::Document.new() do
6
+ @pdf = Prawn::Document.new do
7
7
  text "Page 1. This is the first Chapter. "
8
8
  start_new_page
9
9
  text "Page 2. More in the first Chapter. "
@@ -24,7 +24,7 @@ describe "Outline" do
24
24
  if obj.is_a?(Hash) && obj[:Title]
25
25
  title = obj[:Title].dup
26
26
  title.force_encoding(Encoding::UTF_16LE)
27
- title.valid_encoding?.should == true
27
+ expect(title.valid_encoding?).to eq(true)
28
28
  end
29
29
  end
30
30
  end
@@ -36,55 +36,50 @@ describe "Outline" do
36
36
  end
37
37
 
38
38
  it "should create a root outline dictionary item" do
39
- @outline_root.should_not be_nil
39
+ expect(@outline_root).not_to be_nil
40
40
  end
41
41
 
42
42
  it "should set the first and last top items of the root outline dictionary item" do
43
- referenced_object(@outline_root[:First]).should == @section_1
44
- referenced_object(@outline_root[:Last]).should == @section_1
43
+ expect(referenced_object(@outline_root[:First])).to eq(@section_1)
44
+ expect(referenced_object(@outline_root[:Last])).to eq(@section_1)
45
45
  end
46
46
 
47
47
  describe "#create_outline_item" do
48
48
  it "should create outline items for each section and page" do
49
- [@section_1, @page_1, @page_2].each {|item| item.should_not be_nil}
49
+ [@section_1, @page_1, @page_2].each { |item| expect(item).not_to be_nil }
50
50
  end
51
51
  end
52
52
 
53
53
  describe "#set_relations, #set_variables_for_block, and #reset_parent" do
54
54
  it "should link sibling items" do
55
- referenced_object(@page_1[:Next]).should == @page_2
56
- referenced_object(@page_2[:Prev]).should == @page_1
55
+ expect(referenced_object(@page_1[:Next])).to eq(@page_2)
56
+ expect(referenced_object(@page_2[:Prev])).to eq(@page_1)
57
57
  end
58
58
 
59
59
  it "should link child items to parent item" do
60
- [@page_1, @page_2].each {|page| referenced_object(page[:Parent]).should == @section_1 }
60
+ [@page_1, @page_2].each { |page| expect(referenced_object(page[:Parent])).to eq(@section_1) }
61
61
  end
62
62
 
63
63
  it "should set the first and last child items for parent item" do
64
- referenced_object(@section_1[:First]).should == @page_1
65
- referenced_object(@section_1[:Last]).should == @page_2
64
+ expect(referenced_object(@section_1[:First])).to eq(@page_1)
65
+ expect(referenced_object(@section_1[:Last])).to eq(@page_2)
66
66
  end
67
67
  end
68
68
 
69
69
  describe "#increase_count" do
70
-
71
70
  it "should add the count of all descendant items" do
72
- @outline_root[:Count].should == 3
73
- @section_1[:Count].abs.should == 2
74
- @page_1[:Count].should == 0
75
- @page_2[:Count].should == 0
71
+ expect(@outline_root[:Count]).to eq(3)
72
+ expect(@section_1[:Count].abs).to eq(2)
73
+ expect(@page_1[:Count]).to eq(0)
74
+ expect(@page_2[:Count]).to eq(0)
76
75
  end
77
-
78
76
  end
79
77
 
80
78
  describe "closed option" do
81
-
82
79
  it "should set the item's integer count to negative" do
83
- @section_1[:Count].should == -2
80
+ expect(@section_1[:Count]).to eq(-2)
84
81
  end
85
-
86
82
  end
87
-
88
83
  end
89
84
 
90
85
  describe "adding a custom destination" do
@@ -100,13 +95,12 @@ describe "Outline" do
100
95
  end
101
96
 
102
97
  it "should create an outline item" do
103
- @custom_dest.should_not be_nil
98
+ expect(@custom_dest).not_to be_nil
104
99
  end
105
100
 
106
101
  it "should reference the custom destination" do
107
- referenced_object(@custom_dest[:Dest].first).should == referenced_object(@pages.last)
102
+ expect(referenced_object(@custom_dest[:Dest].first)).to eq(referenced_object(@pages.last))
108
103
  end
109
-
110
104
  end
111
105
 
112
106
  describe "addding a section later with outline#section" do
@@ -122,31 +116,29 @@ describe "Outline" do
122
116
  end
123
117
 
124
118
  it "should add new outline items to document" do
125
- [@section_2, @page_3].each { |item| item.should_not be_nil}
119
+ [@section_2, @page_3].each { |item| expect(item).not_to be_nil }
126
120
  end
127
121
 
128
122
  it "should reset the last items for root outline dictionary" do
129
- referenced_object(@outline_root[:First]).should == @section_1
130
- referenced_object(@outline_root[:Last]).should == @section_2
123
+ expect(referenced_object(@outline_root[:First])).to eq(@section_1)
124
+ expect(referenced_object(@outline_root[:Last])).to eq(@section_2)
131
125
  end
132
126
 
133
127
  it "should reset the next relation for the previous last top level item" do
134
- referenced_object(@section_1[:Next]).should == @section_2
128
+ expect(referenced_object(@section_1[:Next])).to eq(@section_2)
135
129
  end
136
130
 
137
131
  it "should set the previous relation of the addded to section" do
138
- referenced_object(@section_2[:Prev]).should == @section_1
132
+ expect(referenced_object(@section_2[:Prev])).to eq(@section_1)
139
133
  end
140
134
 
141
135
  it "should increase the count of root outline dictionary" do
142
- @outline_root[:Count].should == 5
136
+ expect(@outline_root[:Count]).to eq(5)
143
137
  end
144
-
145
138
  end
146
139
 
147
140
  describe "#outline.add_subsection_to" do
148
141
  context "positioned last" do
149
-
150
142
  before(:each) do
151
143
  @pdf.start_new_page
152
144
  @pdf.text "Page 3. An added subsection "
@@ -161,39 +153,36 @@ describe "Outline" do
161
153
  end
162
154
 
163
155
  it "should add new outline items to document" do
164
- [@subsection, @added_page_3].each { |item| item.should_not be_nil}
156
+ [@subsection, @added_page_3].each { |item| expect(item).not_to be_nil }
165
157
  end
166
158
 
167
159
  it "should reset the last item for parent item dictionary" do
168
- referenced_object(@section_1[:First]).should == @page_1
169
- referenced_object(@section_1[:Last]).should == @subsection
160
+ expect(referenced_object(@section_1[:First])).to eq(@page_1)
161
+ expect(referenced_object(@section_1[:Last])).to eq(@subsection)
170
162
  end
171
163
 
172
164
  it "should set the prev relation for the new subsection to its parent's old last item" do
173
- referenced_object(@subsection[:Prev]).should == @page_2
165
+ expect(referenced_object(@subsection[:Prev])).to eq(@page_2)
174
166
  end
175
167
 
176
-
177
168
  it "the subsection should become the next relation for its parent's old last item" do
178
- referenced_object(@page_2[:Next]).should == @subsection
179
- end
169
+ expect(referenced_object(@page_2[:Next])).to eq(@subsection)
170
+ end
180
171
 
181
172
  it "should set the first relation for the new subsection" do
182
- referenced_object(@subsection[:First]).should == @added_page_3
173
+ expect(referenced_object(@subsection[:First])).to eq(@added_page_3)
183
174
  end
184
175
 
185
176
  it "should set the correct last relation of the added to section" do
186
- referenced_object(@subsection[:Last]).should == @added_page_3
177
+ expect(referenced_object(@subsection[:Last])).to eq(@added_page_3)
187
178
  end
188
179
 
189
180
  it "should increase the count of root outline dictionary" do
190
- @outline_root[:Count].should == 5
181
+ expect(@outline_root[:Count]).to eq(5)
191
182
  end
192
-
193
183
  end
194
184
 
195
185
  context "positioned first" do
196
-
197
186
  before(:each) do
198
187
  @pdf.start_new_page
199
188
  @pdf.text "Page 3. An added subsection "
@@ -208,38 +197,37 @@ describe "Outline" do
208
197
  end
209
198
 
210
199
  it "should add new outline items to document" do
211
- [@subsection, @added_page_3].each { |item| item.should_not be_nil}
200
+ [@subsection, @added_page_3].each { |item| expect(item).not_to be_nil }
212
201
  end
213
202
 
214
203
  it "should reset the first item for parent item dictionary" do
215
- referenced_object(@section_1[:First]).should == @subsection
216
- referenced_object(@section_1[:Last]).should == @page_2
204
+ expect(referenced_object(@section_1[:First])).to eq(@subsection)
205
+ expect(referenced_object(@section_1[:Last])).to eq(@page_2)
217
206
  end
218
207
 
219
208
  it "should set the next relation for the new subsection to its parent's old first item" do
220
- referenced_object(@subsection[:Next]).should == @page_1
209
+ expect(referenced_object(@subsection[:Next])).to eq(@page_1)
221
210
  end
222
211
 
223
212
  it "the subsection should become the prev relation for its parent's old first item" do
224
- referenced_object(@page_1[:Prev]).should == @subsection
225
- end
213
+ expect(referenced_object(@page_1[:Prev])).to eq(@subsection)
214
+ end
226
215
 
227
216
  it "should set the first relation for the new subsection" do
228
- referenced_object(@subsection[:First]).should == @added_page_3
217
+ expect(referenced_object(@subsection[:First])).to eq(@added_page_3)
229
218
  end
230
219
 
231
220
  it "should set the correct last relation of the added to section" do
232
- referenced_object(@subsection[:Last]).should == @added_page_3
221
+ expect(referenced_object(@subsection[:Last])).to eq(@added_page_3)
233
222
  end
234
223
 
235
224
  it "should increase the count of root outline dictionary" do
236
- @outline_root[:Count].should == 5
225
+ expect(@outline_root[:Count]).to eq(5)
237
226
  end
238
-
239
227
  end
240
228
 
241
229
  it "should require an existing title" do
242
- lambda do
230
+ expect do
243
231
  @pdf.go_to_page 1
244
232
  @pdf.start_new_page
245
233
  @pdf.text "Inserted Page"
@@ -249,7 +237,7 @@ describe "Outline" do
249
237
  end
250
238
  end
251
239
  render_and_find_objects
252
- end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
240
+ end.to raise_error(Prawn::Errors::UnknownOutlineTitle)
253
241
  end
254
242
  end
255
243
 
@@ -268,38 +256,35 @@ describe "Outline" do
268
256
 
269
257
  it "should insert new outline items to document" do
270
258
  render_and_find_objects
271
- @inserted_page.should_not be_nil
259
+ expect(@inserted_page).not_to be_nil
272
260
  end
273
261
 
274
262
  it "should adjust the count of all ancestors" do
275
263
  render_and_find_objects
276
- @outline_root[:Count].should == 4
277
- @section_1[:Count].abs.should == 3
264
+ expect(@outline_root[:Count]).to eq(4)
265
+ expect(@section_1[:Count].abs).to eq(3)
278
266
  end
279
267
 
280
268
  describe "#adjust_relations" do
281
-
282
269
  it "should reset the sibling relations of adjoining items to inserted item" do
283
270
  render_and_find_objects
284
- referenced_object(@page_1[:Next]).should == @inserted_page
285
- referenced_object(@page_2[:Prev]).should == @inserted_page
271
+ expect(referenced_object(@page_1[:Next])).to eq(@inserted_page)
272
+ expect(referenced_object(@page_2[:Prev])).to eq(@inserted_page)
286
273
  end
287
274
 
288
275
  it "should set the sibling relation of added item to adjoining items" do
289
276
  render_and_find_objects
290
- referenced_object(@inserted_page[:Next]).should == @page_2
291
- referenced_object(@inserted_page[:Prev]).should == @page_1
277
+ expect(referenced_object(@inserted_page[:Next])).to eq(@page_2)
278
+ expect(referenced_object(@inserted_page[:Prev])).to eq(@page_1)
292
279
  end
293
280
 
294
281
  it "should not affect the first and last relations of parent item" do
295
282
  render_and_find_objects
296
- referenced_object(@section_1[:First]).should == @page_1
297
- referenced_object(@section_1[:Last]).should == @page_2
283
+ expect(referenced_object(@section_1[:First])).to eq(@page_1)
284
+ expect(referenced_object(@section_1[:Last])).to eq(@page_2)
298
285
  end
299
-
300
286
  end
301
287
 
302
-
303
288
  context "when adding another section afterwards" do
304
289
  it "should have reset the root position so that a new section is added at the end of root sections" do
305
290
  @pdf.start_new_page
@@ -310,48 +295,43 @@ describe "Outline" do
310
295
  end
311
296
  end
312
297
  render_and_find_objects
313
- referenced_object(@outline_root[:Last]).should == @section_2
314
- referenced_object(@section_1[:Next]).should == @section_2
298
+ expect(referenced_object(@outline_root[:Last])).to eq(@section_2)
299
+ expect(referenced_object(@section_1[:Next])).to eq(@section_2)
315
300
  end
316
301
  end
317
-
318
- end
319
-
302
+ end
320
303
 
321
304
  describe "inserting at the end of another section" do
322
-
323
305
  before(:each) do
324
306
  @pdf.go_to_page 2
325
- @pdf.start_new_page
326
- @pdf.text "Inserted Page"
327
- @pdf.outline.update do
328
- insert_section_after 'Page 2' do
329
- page :destination => page_number, :title => "Inserted Page"
330
- end
331
- end
332
- render_and_find_objects
307
+ @pdf.start_new_page
308
+ @pdf.text "Inserted Page"
309
+ @pdf.outline.update do
310
+ insert_section_after 'Page 2' do
311
+ page :destination => page_number, :title => "Inserted Page"
312
+ end
313
+ end
314
+ render_and_find_objects
333
315
  end
334
316
 
335
317
  describe "#adjust_relations" do
336
-
337
318
  it "should reset the sibling relations of adjoining item to inserted item" do
338
- referenced_object(@page_2[:Next]).should == @inserted_page
319
+ expect(referenced_object(@page_2[:Next])).to eq(@inserted_page)
339
320
  end
340
321
 
341
322
  it "should set the sibling relation of added item to adjoining items" do
342
- referenced_object(@inserted_page[:Next]).should be_nil
343
- referenced_object(@inserted_page[:Prev]).should == @page_2
323
+ expect(referenced_object(@inserted_page[:Next])).to be_nil
324
+ expect(referenced_object(@inserted_page[:Prev])).to eq(@page_2)
344
325
  end
345
326
 
346
327
  it "should adjust the last relation of parent item" do
347
- referenced_object(@section_1[:Last]).should == @inserted_page
328
+ expect(referenced_object(@section_1[:Last])).to eq(@inserted_page)
348
329
  end
349
-
350
330
  end
351
331
  end
352
332
 
353
333
  it "should require an existing title" do
354
- lambda do
334
+ expect do
355
335
  @pdf.go_to_page 1
356
336
  @pdf.start_new_page
357
337
  @pdf.text "Inserted Page"
@@ -361,28 +341,27 @@ describe "Outline" do
361
341
  end
362
342
  end
363
343
  render_and_find_objects
364
- end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
344
+ end.to raise_error(Prawn::Errors::UnknownOutlineTitle)
365
345
  end
366
-
367
346
  end
368
347
 
369
348
  describe "#page" do
370
349
  it "should require a title option to be set" do
371
- lambda do
372
- @pdf = Prawn::Document.new() do
350
+ expect do
351
+ @pdf = Prawn::Document.new do
373
352
  text "Page 1. This is the first Chapter. "
374
353
  outline.define do
375
354
  page :destination => 1, :title => nil
376
355
  end
377
356
  end
378
- end.should raise_error(Prawn::Errors::RequiredOption)
357
+ end.to raise_error(Prawn::Errors::RequiredOption)
379
358
  end
380
359
  end
381
360
  end
382
361
 
383
362
  describe "foreign character encoding" do
384
363
  before(:each) do
385
- pdf = Prawn::Document.new() do
364
+ pdf = Prawn::Document.new do
386
365
  outline.define do
387
366
  section 'La pomme croquée', :destination => 1, :closed => true
388
367
  end
@@ -392,15 +371,15 @@ describe "foreign character encoding" do
392
371
 
393
372
  it "should handle other encodings for the title" do
394
373
  object = find_by_title('La pomme croquée')
395
- object.should_not == nil
374
+ expect(object).not_to be_nil
396
375
  end
397
376
  end
398
377
 
399
378
  def render_and_find_objects
400
379
  output = StringIO.new(@pdf.render, 'r+')
401
380
  @hash = PDF::Reader::ObjectHash.new(output)
402
- @outline_root = @hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Outlines}
403
- @pages = @hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
381
+ @outline_root = @hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Outlines }
382
+ @pages = @hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
404
383
  @section_1 = find_by_title('Chapter 1')
405
384
  @page_1 = find_by_title('Page 1')
406
385
  @page_2 = find_by_title('Page 2')