File: span_spec.rb

package info (click to toggle)
ruby-prawn 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,220 kB
  • ctags: 826
  • sloc: ruby: 14,469; sh: 43; makefile: 18
file content (43 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# encoding: utf-8

require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")

describe "drawing span" do
  before do
    Prawn.debug = false
    create_pdf
  end

  after do
    Prawn.debug = true
  end

  it "should only accept :position as option in debug mode" do
    Prawn.debug = true
    expect { @pdf.span(350, :x => 3) {} }.to raise_error(Prawn::Errors::UnknownOption)
  end

  it "should have raise an error if :position is invalid" do
    expect { @pdf.span(350, :position => :x) {} }.to raise_error(ArgumentError)
  end

  it "should restore the margin box when bounding box exits" do
    margin_box = @pdf.bounds

    @pdf.span(350, :position => :center) do
      @pdf.text "Here's some centered text in a 350 point column. " * 100
    end

    expect(@pdf.bounds).to eq(margin_box)
  end

  it "should do create a margin box" do
    y = @pdf.y
    margin_box = @pdf.span(350, :position => :center) do
      @pdf.text "Here's some centered text in a 350 point column. " * 100
    end

    expect(margin_box.top).to eq(792.0)
    expect(margin_box.bottom).to eq(0)
  end
end