File: document_spec.rb

package info (click to toggle)
ruby-rghost 0.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,188 kB
  • sloc: ruby: 3,374; makefile: 6; sh: 1
file content (106 lines) | stat: -rw-r--r-- 2,609 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# frozen_string_literal: true

RSpec.describe RGhost::Document do
  it "should to use default options when user doesn't use any" do
    doc = RGhost::Document.new
    r = doc.render :pdf, filename: RGhost.using_temp_dir("testdoc.pdf")
    expect(File.exist?(r.output)).to be true
  end

  it "should create a new document with empty body" do
    doc = RGhost::Document.new
    expect(doc.body.strip).to eq("")
  end

  it "should create a new document using A4 portrait" do
    doc = RGhost::Document.new
    expect(doc.paper.paper).to eq(:A4)
    expect(doc.paper.landscape).to eq(false)
  end

  it "should create a new document using A4 landscape" do
    doc = RGhost::Document.new landscape: true
    expect(doc.paper.paper).to eq(:A4)
    expect(doc.paper.landscape).to eq(true)
  end

  it "should create a new document using custom paper" do
    doc = RGhost::Document.new landscape: true, paper: [10, 20]
    expect(doc.paper.paper).to eq([20, 10])
  end

  it "should get gs paper definitions" do
    doc = RGhost::Document.new paper: [10, 20]
    expect(doc.gs_paper).to eq(["-dDEVICEWIDTHPOINTS=282", "-dDEVICEHEIGHTPOINTS=565"])
  end

  it "should define :rows_per_page" do
    doc = RGhost::Document.new rows_per_page: 40
    doc.variables[:row_padding] == 40
  end

  it "should define :row_height" do
    doc = RGhost::Document.new row_height: 2
    doc.variables[:row_height] == 2
  end

  it "should define :row_padding" do
    doc = RGhost::Document.new row_padding: 1.5
    doc.variables[:row_padding] == 1.5
  end

  it "should define essential libs" do
    libs = [
      "basic.ps",
      "cursor.ps",
      "rectangle.ps",
      "font.ps",
      "textarea.ps",
      "horizontal_line.ps",
      "vertical_line.ps",
      "callbacks.ps",
      "show.ps",
      "eps.ps",
      "jpeg.ps",
      "gif.ps",
      "begin_document.ps",
      "datagrid.ps",
      "text.ps",
      "frame.ps",
      "link.ps",
      "rect_link.ps"
    ]

    doc = RGhost::Document.new

    ps = doc.ps
    libs.each do |libname|
      expect(ps).to include(libname)
    end
  end

  it "should define tags" do
    doc = RGhost::Document.new
    doc.define_tags do
      tag :my_test_tag, name: "Helvetica"
      tag :xxx_test_tag, name: "Helvetica"
    end

    expect(doc.ps).to match "/_xxx_test_tag"
  end

  it "should define functions" do
    doc = RGhost::Document.new
    doc.define :testing_function do |f1|
      f1.set RGhost::PsObject.new("foobar")
    end

    func_def = <<~FUNC.strip
      /_testing_function{
       foobar  
      }
    FUNC

    expect(doc.ps).to include(func_def)
  end
end