Sha256: 81f2171d679fac6c0e74ee1772059256a62474a5cbc779363904d327a915a62f

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

describe Prawn::SVG::Attributes::Transform do
  class TransformTestElement
    include Prawn::SVG::Attributes::Transform

    attr_accessor :attributes, :warnings

    def initialize
      @warnings = []
      @attributes = {}
    end
  end

  let(:element) { TransformTestElement.new }

  describe "#parse_transform_attribute_and_call" do
    subject { element.send :parse_transform_attribute_and_call }

    describe "translate" do
      it "handles a missing y argument" do
        expect(element).to receive(:add_call_and_enter).with('translate', -5.5, 0)
        expect(element).to receive(:distance).with(-5.5, :x).and_return(-5.5)
        expect(element).to receive(:distance).with(0.0, :y).and_return(0.0)

        element.attributes['transform'] = 'translate(-5.5)'
        subject
      end
    end

    describe "rotate" do
      it "handles a single angle argument" do
        expect(element).to receive(:add_call_and_enter).with('rotate', -5.5, :origin => [0, 0])
        expect(element).to receive(:y).with('0').and_return(0)

        element.attributes['transform'] = 'rotate(5.5)'
        subject
      end

      it "handles three arguments" do
        expect(element).to receive(:add_call_and_enter).with('rotate', -5.5, :origin => [1.0, 2.0])
        expect(element).to receive(:x).with(1.0).and_return(1.0)
        expect(element).to receive(:y).with(2.0).and_return(2.0)

        element.attributes['transform'] = 'rotate(5.5 1 2)'
        subject
      end

      it "does nothing and warns if two arguments" do
        expect(element).to receive(:warnings).and_return([])
        element.attributes['transform'] = 'rotate(5.5 1)'
        subject
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prawn-svg-0.24.0 spec/prawn/svg/attributes/transform_spec.rb
prawn-svg-0.23.1 spec/prawn/svg/attributes/transform_spec.rb
prawn-svg-0.23.0 spec/prawn/svg/attributes/transform_spec.rb
prawn-svg-0.22.1 spec/prawn/svg/attributes/transform_spec.rb