From 0fdbd8c74984025098fa8c07d1dfbcd57a4dff6b Mon Sep 17 00:00:00 2001 From: Le1gh Date: Wed, 9 Dec 2020 13:17:52 -0600 Subject: [PATCH] Flesh out Image#clone (#1251) --- spec/rmagick/image/clone_spec.rb | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/spec/rmagick/image/clone_spec.rb b/spec/rmagick/image/clone_spec.rb index d7cff4dce..8fc8f7ddc 100644 --- a/spec/rmagick/image/clone_spec.rb +++ b/spec/rmagick/image/clone_spec.rb @@ -1,15 +1,28 @@ RSpec.describe Magick::Image, "#clone" do - it "works" do - image = described_class.new(20, 20) + it "returns a new copy of the image" do + image = build_image - result = image.clone - expect(result).to be_instance_of(described_class) - expect(image).to eq(result) + new_image = image.clone + + expect(new_image).to eq(image) + expect(new_image).not_to be(image) + expect(new_image.export_pixels).to eq(image.export_pixels) + end + + it "returns a non-frozen copy of the image when it is not frozen" do + image = build_image + + new_image = image.clone + + expect(new_image.frozen?).to be(false) + end + + it "returns a frozen copy of the image when it is frozen" do + image = build_image - result = image.clone - expect(image.frozen?).to eq(result.frozen?) image.freeze - result = image.clone - expect(image.frozen?).to eq(result.frozen?) + new_image = image.clone + + expect(new_image.frozen?).to be(true) end end