Module: ViewComponent::SystemTestHelpers

Includes:
TestHelpers
Included in:
SystemTestCase
Defined in:
lib/view_component/system_test_helpers.rb

Instance Attribute Summary

Attributes included from TestHelpers

#rendered_content

Instance Method Summary collapse

Methods included from TestHelpers

#render_in_view_context, #render_inline, #render_preview, #vc_test_controller, #vc_test_request, #with_controller_class, #with_request_url, #with_variant

Instance Method Details

#with_rendered_component_path(fragment, layout: false, &block) ⇒ Proc

Returns a block that can be used to visit the path of the inline rendered component.

Parameters:

  • fragment (Nokogiri::Fragment)

    The fragment returned from ‘render_inline`.

  • layout (String) (defaults to: false)

    The (optional) layout to use.

Returns:

  • (Proc)

    A block that can be used to visit the path of the inline rendered component.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/view_component/system_test_helpers.rb', line 12

def with_rendered_component_path(fragment, layout: false, &block)
  file = Tempfile.new(
    ["rendered_#{fragment.class.name}", ".html"],
    ViewComponentsSystemTestController.temp_dir
  )
  begin
    file.write(vc_test_controller.render_to_string(html: fragment.to_html.html_safe, layout: layout))
    file.rewind

    block.call("/_system_test_entrypoint?file=#{file.path.split("/").last}")
  ensure
    file.unlink
  end
end