From 37c20e62b44c98c3894bcbfca93e0dad33caf9d0 Mon Sep 17 00:00:00 2001 From: Konrad Date: Mon, 18 Nov 2024 14:55:13 +0100 Subject: [PATCH] feat: add support for nested identifiers for reference images Vips will soon be introduced with its own set of expected render outputs for the same operations, so some mechanism for scoping reference images is needed --- spec/morandi_spec.rb | 7 +++++-- spec/support/match_reference_image.rb | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/morandi_spec.rb b/spec/morandi_spec.rb index ddccd07..aac8a62 100644 --- a/spec/morandi_spec.rb +++ b/spec/morandi_spec.rb @@ -45,7 +45,10 @@ FileUtils.remove_dir('sample/') end - shared_examples 'an image processor' do + shared_examples 'an image processor' do |processor_name| + let(:reference_image_prefix) { processor_name == 'pixbuf' ? '' : processor_name } + subject(:process_image) { Morandi.process(file_arg, options, file_out, { 'processor' => processor_name }) } + describe 'when given an input without any options' do it 'creates output' do process_image @@ -487,7 +490,7 @@ end context 'pixbuf processor' do - it_behaves_like 'an image processor' + it_behaves_like 'an image processor', 'pixbuf' describe 'when given a pixbuf as an input' do subject(:process_image) do diff --git a/spec/support/match_reference_image.rb b/spec/support/match_reference_image.rb index c0f894a..b986942 100644 --- a/spec/support/match_reference_image.rb +++ b/spec/support/match_reference_image.rb @@ -72,8 +72,9 @@ def expose_from(file_type:, tested_path: nil, reference_path: nil, diff_path: ni end end -RSpec::Matchers.define :match_reference_image do |reference_name, file_type: 'jpg', tolerance: 0| - reference_path = File.join('spec/fixtures/reference_images', "#{reference_name}.#{file_type}") +RSpec::Matchers.define :match_reference_image do |*reference_id, file_type: 'jpg', tolerance: 0| + *reference_scope, reference_name = reference_id + reference_path = File.join('spec/fixtures/reference_images', *reference_scope, "#{reference_name}.#{file_type}") def debug_data metadata = RSpec.current_example.metadata