Sha256: de7138e4099e7d94e1fc359716551d3c61d9f323d5a44ac8a38dd76e672d3569

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require File.join(File.dirname(__FILE__), '/../../spec_helper')

describe Imageable do
  
  before(:each) do
    @window = stub :window, :things => []
    Resources.stub! :root => 'some/root'
  end
  
  context 'image defined on class' do
    before(:each) do
      @imageable_class = test_class_with(Imageable) do
        image 'some/path.png'
      end
    end
    it "should define a method lifetime which returns the result of the block" do
      Gosu::Image.stub! :new => :some_image
      
      @imageable_class.new(@window).image.should == :some_image
    end
  end
  context 'sequenced image defined on class' do
    before(:each) do
      @imageable_class = test_class_with(Imageable) do
        sequenced_image 'some/path', :some_width, :some_height, 10.0
      end
    end
    it "should define a method damage which returns the set value" do
      image = stub :image
      sequenced_image = stub :image, :size => 10, :[] => image
      
      Gosu::Image.stub! :load_tiles => sequenced_image
      
      @imageable_class.new(@window).image.should == image
    end
  end
  context 'no image given – what now?' do
    before(:each) do
      @imageable_class = Class.new do
        include Imageable
      end
    end
    it "should raise a ImageMissingError" do
      lambda { @imageable_class.new(@window) }.should raise_error(Imageable::ImageMissingError)
    end
    it "should raise with the right message" do
      lambda { @imageable_class.new(@window) }.should raise_error(Imageable::ImageMissingError, <<-MESSAGE
        
        In an Imageable, you either need to define method
          image path, *args
        for an unchanging image
        or
          sequenced_image path, width, height, frequency = 10, &block
        for a sprite sequence.
        
      MESSAGE
      )
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gosu_extensions-0.3.0 spec/lib/traits/imageable_spec.rb