Sha256: dc6d3cdee0811ce903c682d202ad294540404f529eeddd76131afb9b43a14d2b

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module ViewComponent
  module SystemTestHelpers
    include TestHelpers

    #
    # Returns a block that can be used to visit the path of the inline rendered component.
    # @param fragment [Nokogiri::Fragment] The fragment returned from `render_inline`.
    # @param layout [String] The (optional) layout to use.
    # @return [Proc] A block that can be used to visit the path of the inline rendered component.
    def with_rendered_component_path(fragment, layout: false, &block)
      # Add './tmp/view_components/' directory if it doesn't exist to store the rendered component HTML
      FileUtils.mkdir_p("./tmp/view_components/") unless Dir.exist?("./tmp/view_components/")

      file = Tempfile.new(["rendered_#{fragment.class.name}", ".html"], "tmp/view_components/")
      begin
        file.write(__vc_test_helpers_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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
view_component-3.0.0.rc2 lib/view_component/system_test_helpers.rb