Sha256: 04fab62037df56266269b0676c4ae511d53b05d904dc844baa629ed8f81c4755

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe ChunkyPNG::Dimension do
  subject { ChunkyPNG::Dimension.new(2, 3) }

  it { should respond_to(:width) }
  it { should respond_to(:height) }

  describe '#area' do
    it "should calculate the area correctly" do
      expect(subject.area).to eql 6
    end
  end
end

describe 'ChunkyPNG.Dimension' do
  subject { ChunkyPNG::Dimension.new(1, 2) }

  it "should create a dimension from a 2-item array" do
    expect(ChunkyPNG::Dimension([1, 2])).to     eql subject
    expect(ChunkyPNG::Dimension(['1', '2'])).to eql subject
  end

  it "should create a dimension from a hash with x and y keys" do
    expect(ChunkyPNG::Dimension(:width => 1, :height => 2)).to       eql subject
    expect(ChunkyPNG::Dimension('width' => '1', 'height' => '2')).to eql subject
  end

  it "should create a dimension from a point-like string" do
    [
      ChunkyPNG::Dimension('1,2'),
      ChunkyPNG::Dimension('1   2'),
      ChunkyPNG::Dimension('(1 , 2)'),
      ChunkyPNG::Dimension("{1x2}"),
      ChunkyPNG::Dimension("[1\t2}"),
    ].all? { |point| point == subject }
  end

  it "should create a dimension from an object that responds to width and height" do
    mock_object = Struct.new(:width, :height).new(1, 2)
    expect(ChunkyPNG::Dimension(mock_object)).to eql subject
  end

  it "should raise an exception if the input is not understood" do
    expect { ChunkyPNG::Dimension(Object.new) }.to raise_error(ArgumentError)
    expect { ChunkyPNG::Dimension(1, 2, 3) }.to raise_error(ArgumentError)
  end
end

Version data entries

12 entries across 11 versions & 3 rubygems

Version Path
chunky_png-1.3.11 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.10 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.9 spec/chunky_png/dimension_spec.rb
arcabouco-0.2.13 vendor/bundle/gems/chunky_png-1.3.8/spec/chunky_png/dimension_spec.rb
arcabouco-0.2.13 vendor/bundle/gems/chunky_png-1.3.6/spec/chunky_png/dimension_spec.rb
chunky_png-1.3.8 spec/chunky_png/dimension_spec.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/chunky_png-1.3.7/spec/chunky_png/dimension_spec.rb
chunky_png-1.3.7 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.6 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.5 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.4 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.3 spec/chunky_png/dimension_spec.rb