summaryrefslogtreecommitdiffhomepage
path: root/test/image_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/image_spec.rb')
-rw-r--r--test/image_spec.rb53
1 files changed, 52 insertions, 1 deletions
diff --git a/test/image_spec.rb b/test/image_spec.rb
index 7d4f96d..3abfd04 100644
--- a/test/image_spec.rb
+++ b/test/image_spec.rb
@@ -4,7 +4,58 @@ RSpec.describe Ruby2D::Image do
describe "#new" do
it "raises exception if image file doesn't exist" do
- expect { Image.new("bad_image.png") }.to raise_error(Ruby2D::Error)
+ expect { Image.new('bad_image.png') }.to raise_error(Ruby2D::Error)
+ end
+
+ it "creates an image with a white filter by default" do
+ img = Image.new('test/media/colors.png')
+ expect(img.color).to be_a(Ruby2D::Color)
+ expect(img.color.r).to eq(1)
+ expect(img.color.g).to eq(1)
+ expect(img.color.b).to eq(1)
+ expect(img.color.a).to eq(1)
+ end
+
+ it "creates an image with options" do
+ img = Image.new(
+ 'test/media/colors.png',
+ x: 10, y: 20, z: 30,
+ width: 40, height: 50, rotate: 60,
+ color: 'gray', opacity: 0.5
+ )
+
+ expect(img.path).to eq('test/media/colors.png')
+ expect(img.x).to eq(10)
+ expect(img.y).to eq(20)
+ expect(img.z).to eq(30)
+ expect(img.width).to eq(40)
+ expect(img.height).to eq(50)
+ expect(img.rotate).to eq(60)
+ expect(img.color.r).to eq(2/3.0)
+ expect(img.opacity).to eq(0.5)
+ end
+ end
+
+ describe "attributes" do
+ it "can be set and read" do
+ img = Image.new('test/media/colors.png')
+ img.x = 10
+ img.y = 20
+ img.z = 30
+ img.width = 40
+ img.height = 50
+ img.rotate = 60
+ img.color = 'gray'
+ img.opacity = 0.5
+
+ expect(img.x).to eq(10)
+ expect(img.y).to eq(20)
+ expect(img.z).to eq(30)
+ expect(img.width).to eq(40)
+ expect(img.height).to eq(50)
+ expect(img.rotate).to eq(60)
+ expect(img.color.r).to eq(2/3.0)
+ expect(img.opacity).to eq(0.5)
end
end