Sha256: 943d7f4965c407bda2585bf4205b600c72714046da05d71c583fa9afe681f177

Contents?: true

Size: 953 Bytes

Versions: 10

Compression:

Stored size: 953 Bytes

Contents

# frozen_string_literal: true

require "capybara/minitest"

module ViewComponent
  module TestHelpers
    include Capybara::Minitest::Assertions

    def page
      Capybara::Node::Simple.new(@raw)
    end

    def refute_component_rendered
      assert_no_selector("body")
    end

    def render_inline(component, **args, &block)
      @raw = controller.view_context.render(component, args, &block)

      Nokogiri::HTML.fragment(@raw)
    end

    def controller
      @controller ||= Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
    end

    def request
      @request ||= ActionDispatch::TestRequest.create
    end

    def with_variant(variant)
      old_variants = controller.view_context.lookup_context.variants

      controller.view_context.lookup_context.variants = variant
      yield
      controller.view_context.lookup_context.variants = old_variants
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
view_component-2.3.0 lib/view_component/test_helpers.rb
view_component-2.2.2 lib/view_component/test_helpers.rb
view_component-2.2.1 lib/view_component/test_helpers.rb
view_component-2.2.0 lib/view_component/test_helpers.rb
view_component-2.1.0 lib/view_component/test_helpers.rb
view_component-2.0.0 lib/view_component/test_helpers.rb
view_component-1.17.0 lib/view_component/test_helpers.rb
actionview-component-1.17.0 lib/view_component/test_helpers.rb
view_component-1.16.0 lib/view_component/test_helpers.rb
actionview-component-1.16.0 lib/view_component/test_helpers.rb