Sha256: 468fdf30cd9556e5a2f0934634b839b4918c1d798ef7a8417634f52c4ec36d05

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe FormatParser::PDFParser do
  let(:parsed_pdf) {
    subject.call(
      File.open(
        Pathname.new(fixtures_dir).join('PDF').join(pdf_file),
        'rb'
      )
    )
  }

  shared_examples :behave_like_pdf do |hash|
    let(:pdf_file) { hash.fetch(:file) }

    it 'acts as a pdf' do
      expect(parsed_pdf).not_to be_nil
      expect(parsed_pdf.nature).to eq(:document)
      expect(parsed_pdf.format).to eq(:pdf)
    end

    it 'has a correct page count' do
      expect(parsed_pdf.page_count).to eq(hash.fetch(:page_count))
    end
  end

  describe 'a PDF file with a missing version header' do
    let(:pdf_file) { 'not_a.pdf' }

    it 'does not parse succesfully' do
      expect(parsed_pdf).to be_nil
    end
  end

  describe 'a PDF file with a correct header but no valid content' do
    let(:pdf_file) { 'broken.pdf' }

    pending 'does not parse succesfully'
  end

  describe 'exceeding the PDF read limit' do
    let(:pdf_file) { 'read_limit.pdf' }

    pending 'does not parse succesfully'
  end

  describe 'a PDF file with a missing COUNT_HEADER' do
    let(:pdf_file) { 'missing_page_count.pdf' }

    it 'does not return a page count' do
      expect(parsed_pdf.page_count).to eq(nil)
    end
  end

  describe 'parses a PDF file' do
    describe 'a single page file' do
      include_examples :behave_like_pdf, file: '1_page.pdf', page_count: 1
    end

    describe 'a multi page pdf file' do
      include_examples :behave_like_pdf, file: '2_pages.pdf', page_count: 2
    end

    describe 'a multi page pdf file with content' do
      include_examples :behave_like_pdf, file: '10_pages.pdf', page_count: 10
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
format_parser-0.13.6 spec/parsers/pdf_parser_spec.rb
format_parser-0.13.5 spec/parsers/pdf_parser_spec.rb
format_parser-0.13.4 spec/parsers/pdf_parser_spec.rb
format_parser-0.13.3 spec/parsers/pdf_parser_spec.rb
format_parser-0.13.2 spec/parsers/pdf_parser_spec.rb
format_parser-0.13.1 spec/parsers/pdf_parser_spec.rb
format_parser-0.13.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.12.4 spec/parsers/pdf_parser_spec.rb
format_parser-0.12.2 spec/parsers/pdf_parser_spec.rb
format_parser-0.12.1 spec/parsers/pdf_parser_spec.rb
format_parser-0.12.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.11.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.10.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.9.4 spec/parsers/pdf_parser_spec.rb
format_parser-0.9.3 spec/parsers/pdf_parser_spec.rb
format_parser-0.9.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.8.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.7.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.6.0 spec/parsers/pdf_parser_spec.rb
format_parser-0.5.2 spec/parsers/pdf_parser_spec.rb