diff --git a/lib/arbre/rails/rendering.rb b/lib/arbre/rails/rendering.rb index 33ea6826..9e7e8b5b 100644 --- a/lib/arbre/rails/rendering.rb +++ b/lib/arbre/rails/rendering.rb @@ -3,8 +3,8 @@ module Arbre module Rails module Rendering - def render(*args) - rendered = helpers.render(*args) + def render(*args, &block) + rendered = helpers.render(*args, &block) case rendered when Arbre::Context current_arbre_element.add_child rendered diff --git a/spec/rails/integration/rendering_spec.rb b/spec/rails/integration/rendering_spec.rb index 35832e04..08097b81 100644 --- a/spec/rails/integration/rendering_spec.rb +++ b/spec/rails/integration/rendering_spec.rb @@ -31,6 +31,10 @@ def render_partial_with_instance_variable @my_instance_var = "From Instance Var" render "arbre/page_with_arb_partial_and_assignment" end + + def render_with_block + render "arbre/page_with_render_with_block" + end end RSpec.describe TestController, "Rendering with Arbre", type: :request do @@ -45,6 +49,7 @@ def render_partial_with_instance_variable get 'test/render_with_instance_variable', controller: "test" get 'test/render_partial_with_instance_variable', controller: "test" get 'test/render_page_with_helpers', controller: "test" + get 'test/render_with_block', controller: "test" end end @@ -96,4 +101,14 @@ def render_partial_with_instance_variable expect(body).to have_css("p", text: "Partial: From Instance Var") end + it "renders with a block" do + get "/test/render_with_block" + expect(response).to be_successful + expect(body).to eq <<~HTML +

Before Render

+ Hello from a render block +

After Render

+ HTML + end + end diff --git a/spec/rails/templates/arbre/page_with_render_with_block.arb b/spec/rails/templates/arbre/page_with_render_with_block.arb new file mode 100644 index 00000000..e5c78e3c --- /dev/null +++ b/spec/rails/templates/arbre/page_with_render_with_block.arb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +render_in_object = Class.new do + def render_in(_, &block) + block.call + end +end.new + +h1 "Before Render" +render render_in_object do + "Hello from a render block\n" +end +h2 "After Render"