Sha256: 29ef37a770c23a016685a9a808f448f8b0969261f54ea261f3355e2bad9b3005

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

describe Ray::Image do
  before :each do
    Ray.init
    @win = Ray.create_window(:w => 100, :h => 100)
  end

  describe "#blit" do
    context "when trying to blit on a non-surface" do
      it "should raise a type error" do
        img = Ray::Image.new(:w => 50, :h => 50)
        lambda {
          img.blit(:on => Ray::Color.new(10, 20, 30))
        }.should raise_exception(TypeError)
      end
    end

    context "when trying to use a non-rect as a position" do
      it "should raise a type error" do
        img = Ray::Image.new(:w => 50, :h => 50)
        lambda {
          img.blit(:from => Ray::Color.new(10, 20, 30), :on => @win)
        }.should raise_exception(TypeError)

        lambda {
          img.blit(:on => @win, :at => Ray::Color.new(10, 20, 30))
        }.should raise_exception(TypeError)
      end
    end
  end

  describe "#initialize" do
    context "when the argument isn't a hash or a string" do
      it "should raise a type error" do
        lambda {
          Ray::Image.new(3)
        }.should raise_exception(TypeError)
      end
    end

    context "when loading an existing file" do
      it "should not raise an error" do
        lambda {
          Ray::Image.new(path_of("aqua.bmp"))
        }.should_not raise_exception
      end
    end

    context "when loading an unexising file" do
      it "should raise a runtime error" do
        lambda {
          Ray::Image.new("does_not_exist.bmp")
        }.should raise_exception
      end
    end

    if Ray.has_image_support?
      it "should be able to load other formats" do
        lambda {
          Ray::Image.new(path_of("aqua.png"))
        }.should_not raise_exception
      end

      context "if the extension does not match the file type" do
        it "should still load it correctly" do
          lambda {
            Ray::Image.new(path_of("not_a_jpeg.jpeg"))
          }.should_not raise_exception
        end
      end
    end
  end

  after :each do
    Ray.stop
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ray-0.0.0.pre2 spec/ray/image_spec.rb