From d910023a65a5c8117f924ba8c1c8fbbf4c1dcaab Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Thu, 19 Feb 2026 03:53:31 +0100 Subject: [PATCH 1/2] Ensure `Herb::Engine` produces valid Ruby in snapshot tests --- test/snapshot_utils.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/snapshot_utils.rb b/test/snapshot_utils.rb index a6b8701..6772057 100644 --- a/test/snapshot_utils.rb +++ b/test/snapshot_utils.rb @@ -7,6 +7,7 @@ require "readline" require "digest" require "json" +require "prism" def ask?(prompt = "") Readline.readline("===> #{prompt}? (y/N) ", true).squeeze(" ").strip == "y" @@ -25,6 +26,18 @@ def assert_compiled_snapshot(source, handler: ReActionView::Template::Handlers:: compiled_source = template.handler.call(template, source) + prism_result = Prism.parse(compiled_source) + syntax_errors = prism_result.errors.reject { |e| e.type == :invalid_yield } + + assert syntax_errors.empty?, <<~MESSAGE + Compiled output is not valid Ruby: + + #{syntax_errors.map { |e| " - #{e.message} (line #{e.location.start_line})" }.join("\n")} + + Compiled source: + #{compiled_source} + MESSAGE + snapshot_key = JSON.generate({ source: source, handler: handler, @@ -51,6 +64,18 @@ def assert_evaluated_snapshot(source, ivars: {}, options: {}, handler: ReActionV compiled_source = template.handler.call(template, source) + prism_result = Prism.parse(compiled_source) + syntax_errors = prism_result.errors.reject { |e| e.type == :invalid_yield } + + assert syntax_errors.empty?, <<~MESSAGE + Compiled output is not valid Ruby: + + #{syntax_errors.map { |e| " - #{e.message} (line #{e.location.start_line})" }.join("\n")} + + Compiled source: + #{compiled_source} + MESSAGE + lookup_context = ActionView::LookupContext.new([]) view_context = ActionView::Base.with_empty_template_cache.new(lookup_context, {}, nil) From 1fc84a18226123447d582d25c5961990772032c5 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Thu, 19 Feb 2026 03:56:40 +0100 Subject: [PATCH 2/2] RuboCop --- test/snapshot_utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/snapshot_utils.rb b/test/snapshot_utils.rb index 6772057..528f27b 100644 --- a/test/snapshot_utils.rb +++ b/test/snapshot_utils.rb @@ -52,7 +52,7 @@ def assert_compiled_snapshot(source, handler: ReActionView::Template::Handlers:: compiled_source end - def assert_evaluated_snapshot(source, ivars: {}, options: {}, handler: ReActionView::Template::Handlers::ERB, virtual_path: "test", format: :html, locals: []) # rubocop:disable Metrics/ParameterLists,Layout/LineLength + def assert_evaluated_snapshot(source, ivars: {}, options: {}, handler: ReActionView::Template::Handlers::ERB, virtual_path: "test", format: :html, locals: []) # rubocop:disable Metrics/ParameterLists,Layout/LineLength,Metrics/MethodLength template = ActionView::Template.new( source, "test_template",