From 80f5bb154476d0ece996b49dc6703fb182b7f84b Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 8 Aug 2026 05:40:51 +0200 Subject: [PATCH] Add regression test for heredoc with trailing arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The compiled Ruby for an ERB expression containing a heredoc needs the closing parenthesis on its own line after the heredoc terminator. That is handled by `Herb::Engine#trailing_newline`, but the handler override in `ReActionView::Template::Handlers::Herb::Herb#add_expression` had no test covering it. Ported from #78 by @pinzonjulian, which is otherwise obsolete since the fix landed upstream in marcoroth/herb#1206. Co-authored-by: Julián Pinzón Eslava --- ...by_compiled_ffc55de9e7891578a81f0a2b0c1346a5.txt | 8 ++++++++ test/template/handlers/herb_test.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/snapshots/herb/template_handler_test/test_0031_heredoc_with_trailing_arguments_compiles_to_valid_Ruby_compiled_ffc55de9e7891578a81f0a2b0c1346a5.txt diff --git a/test/snapshots/herb/template_handler_test/test_0031_heredoc_with_trailing_arguments_compiles_to_valid_Ruby_compiled_ffc55de9e7891578a81f0a2b0c1346a5.txt b/test/snapshots/herb/template_handler_test/test_0031_heredoc_with_trailing_arguments_compiles_to_valid_Ruby_compiled_ffc55de9e7891578a81f0a2b0c1346a5.txt new file mode 100644 index 0000000..12e6535 --- /dev/null +++ b/test/snapshots/herb/template_handler_test/test_0031_heredoc_with_trailing_arguments_compiles_to_valid_Ruby_compiled_ffc55de9e7891578a81f0a2b0c1346a5.txt @@ -0,0 +1,8 @@ + @output_buffer.append=(method_call <<~GRAPHQL, variables + query { + field + } +GRAPHQL +); + @output_buffer.safe_append=' +'.freeze;@output_buffer \ No newline at end of file diff --git a/test/template/handlers/herb_test.rb b/test/template/handlers/herb_test.rb index 1da0252..8a1ce8e 100644 --- a/test/template/handlers/herb_test.rb +++ b/test/template/handlers/herb_test.rb @@ -366,6 +366,19 @@ def @view_context.ui_badge(count, **_options) assert_compiled_snapshot(template) end + test "heredoc with trailing arguments compiles to valid Ruby" do + template = <<~ERB + <%= method_call <<~GRAPHQL, variables + query { + field + } + GRAPHQL + %> + ERB + + assert_compiled_snapshot(template) + end + test "renders templates that are not local with ActionView's ERB handler" do ReActionView.config.intercept_erb = true