summaryrefslogtreecommitdiffhomepage
path: root/test/image_spec.rb
blob: 3abfd046b0645e22d5f78b1d8c1b2e87b6e3a065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'ruby2d'

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)
    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

end