Sha256: 290b370c254d8f720155ea55a63c55f6162515d39aaf5248f29ef026f81127b3

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 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
      subject.area.should == 6
    end
  end
end

describe 'ChunkyPNG.Dimension' do
  subject { ChunkyPNG::Dimension.new(1, 2) }
  
  it "should create a point from a 2-item array" do
    ChunkyPNG::Dimension([1, 2]).should     == subject
    ChunkyPNG::Dimension(['1', '2']).should == subject
  end
  
  it "should create a point from a hash with x and y keys" do
    ChunkyPNG::Dimension(:width => 1, :height => 2).should       == subject
    ChunkyPNG::Dimension('width' => '1', 'height' => '2').should == subject
  end
  
  it "should create a point 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 raise an exception if the input is not understood" do
    lambda { ChunkyPNG::Dimension(Object.new) }.should raise_error(ChunkyPNG::ExpectationFailed)
    lambda { ChunkyPNG::Dimension(1, 2, 3) }.should raise_error(ChunkyPNG::ExpectationFailed)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chunky_png-1.0.0.rc1 spec/chunky_png/dimension_spec.rb