diff --git a/spec/colour_helper.rb b/spec/colour_helper.rb index 2cb7878..04acf46 100644 --- a/spec/colour_helper.rb +++ b/spec/colour_helper.rb @@ -16,25 +16,12 @@ def generate_test_image_greyscale(at_file_path, width: 600, height: 300) def generate_test_image(at_file_path, fill:, width: 600, height: 300) fill = Array(fill).flatten - system( - 'convert', - '-size', - "#{width}x#{height}", - '-seed', - '5432', - *fill, - at_file_path - ) + generate_image_options = ['convert', '-size', "#{width}x#{height}", '-seed', '5432', *fill, at_file_path] + system(*generate_image_options) || raise("Failed to generate image.\nCommand: #{generate_image_options.join(' ')}") end - def solid_colour_image(width, height, colour = 0x000000ff) - pb = GdkPixbuf::Pixbuf.new(colorspace: GdkPixbuf::Colorspace::RGB, - has_alpha: false, - bits_per_sample: 8, - width: width, - height: height) - pb.fill!(colour) - pb + def generate_test_image_solid(at_file_path, width: 600, height: 300, colour: '#000000') + generate_test_image(at_file_path, width: width, height: height, fill: "canvas:#{colour}") end def crude_average_colour(pixbuf) diff --git a/spec/morandi_spec.rb b/spec/morandi_spec.rb index 140bd7c..ddccd07 100644 --- a/spec/morandi_spec.rb +++ b/spec/morandi_spec.rb @@ -578,7 +578,10 @@ end context 'with a gray image and invalid spots' do - let(:file_arg) { solid_colour_image(800, 800, 0x666666ff) } + let(:file_in) { 'sample/sample.jpg' } + let(:original_image_width) { 800 } + let(:original_image_height) { 800 } + let(:generate_image) { generate_test_image_solid(file_in, width: 800, height: 800, colour: '#666666') } let(:options) { { 'redeye' => [[540, 650], [-100, 100]] } } it 'should not break or corrupt the image' do @@ -587,9 +590,9 @@ expect(File).to exist(file_out) expect(processed_image_type).to eq('jpeg') - expect(crude_average_colour(file_arg.subpixbuf(505, 605, 100, 100))).to be_greyish - expect(crude_average_colour(GdkPixbuf::Pixbuf.new(file: file_out).subpixbuf(505, 605, 100, - 100))).to be_greyish + expect(crude_average_colour(GdkPixbuf::Pixbuf.new(file: file_in).subpixbuf(505, 605, 100, 100))).to be_greyish + expect(crude_average_colour(GdkPixbuf::Pixbuf.new(file: file_out).subpixbuf(505, 605, 100, 100))) + .to be_greyish end end end