Sha256: d54cb3295ff260eda559983203e225a76b22b935c73ce62096f7f2d6844a0c4e

Contents?: true

Size: 1.99 KB

Versions: 6

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe "DotGrid::Document" do
  describe "#initialize" do
    let(:subject) { DotGrid::Document.new({}) }

    it "has a default file name" do
      expect(subject.file_name).to eq("dotgrid.pdf")
    end

    it "has a default file page size" do
      expect(subject.page_size).to eq("LETTER")
    end

    it "has a default file page orientation" do
      expect(subject.orientation).to eq(:portrait)
    end

    it "has a default file margin" do
      expect(subject.margin).to eq(0.0)
    end

    it "creates a pdf file" do
      expect(subject.pdf).to be_a(Prawn::Document)
    end

    it "creates the pages" do
      expect(subject.page_types).to have(1).page
    end
  end

  describe "#parse_page_size" do
    context "when the page size doesn't match the regex" do
      let(:subject) { DotGrid::Document.new({page_size: "LEGAL"}) }

      it "returns the page_size as is" do
        expect(subject.page_size).to eq("LEGAL")
      end
    end

    context "when the page size matches the regex" do
      let(:subject) { DotGrid::Document.new({page_size: "4x5in"}) }

      it "returns the width and heigth in an array" do
        expect(subject.page_size).to have(2).elements
      end

      it "translates the width to points" do
        expect(subject.page_size[0]).to eq(4.in)
      end

      it "translates the height to points" do
        expect(subject.page_size[1]).to eq(5.in)
      end
    end
  end

  describe "#create_pages" do
    it "calls the factory for each page" do
      expect(DotGrid::Page::Factory).to receive(:build).twice
      DotGrid::Document.new({page_types: "a, b"})
    end
  end

  describe "#generate" do
    let(:subject) { DotGrid::Document.new({}) }

    before do
      allow(subject.pdf).to receive(:render_file)
    end

    it "generates each of the pages" do
      expect(subject.pages[0]).to receive(:generate)
      subject.generate
    end

    it "renders the pdf" do
      expect(subject.pdf).to receive(:render_file)
      subject.generate
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dot_grid-0.0.12 spec/lib/dot_grid/document_spec.rb
dot_grid-0.0.11 spec/lib/dot_grid/document_spec.rb
dot_grid-0.0.10 spec/lib/dot_grid/document_spec.rb
dot_grid-0.0.9 spec/lib/dot_grid/document_spec.rb
dot_grid-0.0.8 spec/lib/dot_grid/document_spec.rb
dot_grid-0.0.7 spec/lib/dot_grid/document_spec.rb