File: rspec.rb

package info (click to toggle)
ruby-pdf-reader 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,908 kB
  • ctags: 569
  • sloc: ruby: 8,330; makefile: 10
file content (32 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env ruby
# coding: utf-8

#  Basic RSpec of a generated PDF
#
#  USAGE: rspec -c examples/rspec.rb

require 'pdf/reader'
require 'rspec'
require 'prawn'
require 'stringio'

describe "My generated PDF" do
  it "should have the correct text on 2 pages" do

    # generate our PDF
    pdf = Prawn::Document.new
    pdf.text "Chunky"
    pdf.start_new_page
    pdf.text "Bacon"
    io = StringIO.new(pdf.render)

    # process the PDF
    PDF::Reader.open(io) do |reader|
      reader.page_count.should eql(2)          # correct page count

      reader.page(1).text.should eql("Chunky") # correct content
      reader.page(2).text.should eql("Bacon")  # correct content
    end

  end
end