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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
RSpec.describe Magick::Image, '#composite' do
it 'raises an error given invalid arguments' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
expect { image1.composite }.to raise_error(ArgumentError)
expect { image1.composite(image2) }.to raise_error(ArgumentError)
expect do
image1.composite(image2, Magick::NorthWestGravity)
end.to raise_error(ArgumentError)
expect { image1.composite(2) }.to raise_error(ArgumentError)
expect { image1.composite(image2, 2) }.to raise_error(ArgumentError)
end
context 'when given 3 arguments' do
it 'works when 2nd argument is a gravity' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
Magick::CompositeOperator.values do |op|
Magick::GravityType.values do |grav|
expect { image1.composite(image2, grav, op) }.not_to raise_error
end
end
end
it 'accepts an ImageList argument' do
image = described_class.new(20, 20)
image_list = Magick::ImageList.new
image_list.new_image(10, 10)
expect { image.composite(image_list, Magick::NorthWestGravity, Magick::OverCompositeOp) }.not_to raise_error
end
it 'raises an error when 2nd argument is not a gravity' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
expect do
image1.composite(image2, 2, Magick::OverCompositeOp)
end.to raise_error(TypeError)
end
end
context 'when given 4 arguments' do
it 'works when 4th argument is a composite operator' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
# there are way too many CompositeOperators to test them all, so just try
# few representative ops
Magick::CompositeOperator.values do |op|
expect { image1.composite(image2, 0, 0, op) }.not_to raise_error
end
end
it 'accepts an ImageList argument' do
image = described_class.new(20, 20)
image_list = Magick::ImageList.new
image_list.new_image(10, 10)
expect { image.composite(image_list, 0, 0, Magick::OverCompositeOp) }.not_to raise_error
end
it 'returns a new Magick::Image object' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
result = image1.composite(image2, 0, 0, Magick::OverCompositeOp)
expect(result).to be_instance_of(described_class)
end
it 'raises an error when 4th argument is not a composite operator' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
expect { image1.composite(image2, 0, 0, 2) }.to raise_error(TypeError)
end
end
context 'when given 5 arguments' do
it 'works when 2nd argument is gravity and 5th is a composite operator' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
Magick::CompositeOperator.values do |op|
Magick::GravityType.values do |grav|
expect { image1.composite(image2, grav, 0, 0, op) }.not_to raise_error
end
end
end
it 'accepts an ImageList argument' do
image = described_class.new(20, 20)
image_list = Magick::ImageList.new
image_list.new_image(10, 10)
expect { image.composite(image_list, Magick::NorthWestGravity, 0, 0, Magick::OverCompositeOp) }.not_to raise_error
end
it 'raises an error when 2nd argument is not a gravity' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
expect do
image1.composite(image2, 0, 0, 2, Magick::OverCompositeOp)
end.to raise_error(TypeError)
end
end
it 'raises an error when the image has been destroyed' do
image1 = described_class.read(IMAGES_DIR + '/Button_0.gif').first
image2 = described_class.read(IMAGES_DIR + '/Button_1.gif').first
image2.destroy!
expect do
image1.composite(image2, Magick::CenterGravity, Magick::OverCompositeOp)
end.to raise_error(Magick::DestroyedImageError)
end
end
|