Sha256: 45039d7fbe111f2a424673285d3ca99b672f1748565e5fdb820bc857eaa0da98

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Prawn::View do
  let(:view_object) { Object.new.tap { |o| o.extend(described_class) } }

  it 'provides a Prawn::Document object by default' do
    expect(view_object.document).to be_kind_of(Prawn::Document)
  end

  it 'delegates unhandled methods to object returned by document method' do
    doc = instance_double('Document')
    allow(view_object).to receive(:document).and_return(doc)

    allow(doc).to receive(:some_delegated_method)

    view_object.some_delegated_method

    expect(doc).to have_received(:some_delegated_method)
  end

  it 'allows a block-like DSL via the update method' do
    doc = instance_double('Document')
    allow(view_object).to receive(:document).and_return(doc)

    allow(doc).to receive(:foo)
    allow(doc).to receive(:bar)

    view_object.update do
      foo
      bar
    end
    expect(doc).to have_received(:foo)
    expect(doc).to have_received(:bar)
  end

  it 'aliases save_as() to document.render_file()' do
    doc = instance_double('Document')
    allow(doc).to receive(:render_file)

    allow(view_object).to receive(:document).and_return(doc)

    view_object.save_as('foo.pdf')
    expect(doc).to have_received(:render_file)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prawn-2.2.2 spec/prawn/view_spec.rb
prawn-2.2.1 spec/prawn/view_spec.rb
prawn-2.2.0 spec/prawn/view_spec.rb