require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb' context Ray::Image do setup { Ray::Image } context "created with a hash" do setup { topic.new(:w => 50, :h => 70) } asserts(:w).equals(50) asserts(:h).equals(70) end denies("creating from a file") { topic.new(path_of("aqua.bmp")) }.raises(RuntimeError) asserts("creating from a non-existing file") { topic.new(path_of("doesnt_exist.bmp")) }.raises(RuntimeError) denies("creating from an IO object") { open(path_of("aqua.bmp")) { |io| topic.new(io) } }.raises(RuntimeError) asserts("creating from an invalid IO object") { open(path_of("VeraMono.ttf")) { |io| topic.new(io) } }.raises(RuntimeError) denies "two different images are equal, despite their content" do a = topic.new(:w => 10, :h => 10).fill(Ray::Color.red).update b = topic.new(:w => 10, :h => 10).fill(Ray::Color.red).update a == b end asserts "two images representing the same one are equal" do Ray.screen == Ray.screen end end context "an image" do setup { Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.green).update } asserts(:size).equals Ray::Vector2[10, 10] asserts("#dup returns a copy of the receiver") { topic.dup != topic } asserts("a pixel outside the image") { topic[10, 10] }.nil asserts("a pixel inside the image is a Ray::Color") { topic[5, 5].is_a? Ray::Color } asserts("setting a pixel outside the image") { topic.lock { topic[10, 10] = Ray::Color.red } }.raises(ArgumentError) denies("setting a pixel outside the image") { topic { topic[5, 5] = Ray::Color.red } }.raises(RuntimeError) asserts("setting a pixel in a non-locked image") { topic[5, 5] = Ray::Color.red }.raises(RuntimeError) context "after having changed a pixel" do hookup { topic.lock { topic[3, 2] = Ray::Color.green } } asserts("the changed pixel") { topic[3, 2] }.equals(Ray::Color.green) end asserts(:clip).equals(Ray::Rect.new(0, 0, 10, 10)) context "after having changed the clipping rect" do hookup { topic.clip([5, 5, 3, 3]) } asserts(:clip).equals(Ray::Rect.new(5, 5, 3, 3)) end asserts("clip inside a block and otside the block") { res = [] topic.clip([5, 5, 3, 3]) { res << topic.clip } res << topic.clip }.equals([Ray::Rect.new(5, 5, 3, 3), Ray::Rect.new(0, 0, 10, 10)]) end run_tests if __FILE__ == $0