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
|
RSpec.describe Magick::Image, "#change_geometry" do
it "passes the original image to the block" do
image = build_image
block_image = nil
image.change_geometry('400x400') do |_cols, _rows, inner_image|
block_image = inner_image
end
expect(block_image).to be(image)
end
it "returns the result from the block" do
image = build_image
result = image.change_geometry('400x400') { "some_result" }
expect(result).to eq("some_result")
end
it "does not directly modify the original image" do
image = build_image
image.change_geometry('400x400') {}
expect([image.rows, image.columns]).to eq([2, 2])
end
it "passes dimensions to enable enlarging the image" do
image = build_image
resized_image = image.change_geometry('400x400') do |cols, rows, block_image|
block_image.resize(cols, rows)
end
expect([resized_image.rows, resized_image.columns]).to eq([400, 400])
end
it "passes dimensions that will maintain the aspect ratio" do
image = build_image
image.change_geometry('300x4000') do |cols, rows|
image.resize!(cols, rows)
end
expect([image.rows, image.columns]).to eq([300, 300])
end
it "accepts a Geometry object that maintains the aspect ratio" do
image = build_image
image.change_geometry(Magick::Geometry.new(300, 4000)) do |cols, rows|
image.resize!(cols, rows)
end
expect([image.rows, image.columns]).to eq([300, 300])
end
it "raises an error when extra arguments are passed" do
image = build_image
expect { image.change_geometry('400x400', "boo") {} }
.to raise_error(ArgumentError)
end
it "raises an error when no block is passed" do
image = build_image
expect { image.change_geometry('400x400') }
.to raise_error(LocalJumpError)
end
end
|