summaryrefslogtreecommitdiffhomepage
path: root/test/image_spec.rb
blob: e2ef37eb4085df34404587c932393c6f1abce3ef (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
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
  end

  describe "#contains?" do
    it "returns true if point is inside the image" do
      image = Image.new("test/media/image.bmp")
      expect(image.contains?(50, 50)).to be true
    end

    it "returns true if point is outside the image" do
      image = Image.new("test/media/image.bmp")
      expect(image.contains?(-50, 50)).to be false
      expect(image.contains?(50, -50)).to be false
      expect(image.contains?(50, 150)).to be false
      expect(image.contains?(150, 50)).to be false
    end
  end

end