Sha256: a0b57f456e4fee745e9a2e50b3aede44ede382abe3943792b71b4d0049b6af1d

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

RSpec.describe Prawn::SVG::Loaders::Data do
  let(:uri) { URI(url) }

  subject { Prawn::SVG::Loaders::Data.new.from_url(url) }

  context 'with a valid image/png data URL' do
    let(:url) { 'data:image/png;base64,aGVsbG8=' }

    it 'loads the data' do
      expect(subject).to eq 'hello'
    end
  end

  context 'with a valid image/jpeg data URL' do
    let(:url) { 'data:image/jpeg;base64,aGVsbG8=' }

    it 'loads the data' do
      expect(subject).to eq 'hello'
    end
  end

  context 'with a data URL that has extra metadata' do
    let(:url) { 'data:image/png;base64;metadata;here,aGVsbG8=' }

    it 'loads the data' do
      expect(subject).to eq 'hello'
    end
  end

  context "with a data URL that's uppercase" do
    let(:url) { 'DATA:IMAGE/PNG;BASE64;METADATA;HERE,aGVsbG8=' }

    it 'loads the data' do
      expect(subject).to eq 'hello'
    end
  end

  context "with a URL that's not a data scheme" do
    let(:url) { 'http://some.host' }

    it 'returns nil' do
      expect(subject).to be nil
    end
  end

  context "with a data URL that's not an image" do
    let(:url) { 'data:application/pdf;base64,aGVsbG8=' }

    it 'raises' do
      expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /image/
    end
  end

  context "with a data URL that's not base64 encoded" do
    let(:url) { 'data:image/png;base32,agvsbg' }

    it 'raises' do
      expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /base64/
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prawn-svg-0.36.0 spec/prawn/svg/loaders/data_spec.rb
prawn-svg-0.35.1 spec/prawn/svg/loaders/data_spec.rb
prawn-svg-0.35.0 spec/prawn/svg/loaders/data_spec.rb