Sha256: 7ab62ad355aa84f9b69d9417cdac41bbddb95e3a0deffab65613d9ff8ba2a9f5

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 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 dimension from a 2-item array" do
    ChunkyPNG::Dimension([1, 2]).should     == subject
    ChunkyPNG::Dimension(['1', '2']).should == subject
  end
  
  it "should create a dimension 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 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)
    ChunkyPNG::Dimension(mock_object).should == subject
  end
  
  it "should raise an exception if the input is not understood" do
    lambda { ChunkyPNG::Dimension(Object.new) }.should raise_error(ArgumentError)
    lambda { ChunkyPNG::Dimension(1, 2, 3) }.should raise_error(ArgumentError)
  end
end

Version data entries

7 entries across 6 versions & 3 rubygems

Version Path
bench9000-0.1 vendor/chunky_png/spec/chunky_png/dimension_spec.rb
chunky_png-1.3.2 spec/chunky_png/dimension_spec.rb
chunky_png-1.3.1 spec/chunky_png/dimension_spec.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/chunky_png-1.3.0/spec/chunky_png/dimension_spec.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/chunky_png-1.3.0/spec/chunky_png/dimension_spec.rb
chunky_png-1.3.0 spec/chunky_png/dimension_spec.rb
chunky_png-1.2.9 spec/chunky_png/dimension_spec.rb