Module: ViewComponent::TestHelpers
- Included in:
- TestCase
- Defined in:
- lib/view_component/test_helpers.rb
Instance Attribute Summary collapse
-
#rendered_component ⇒ Object
readonly
Returns the value of attribute rendered_component.
Instance Method Summary collapse
- #controller ⇒ Object
- #render_inline(component, **args, &block) ⇒ Object
- #request ⇒ Object
- #with_variant(variant) ⇒ Object
Instance Attribute Details
#rendered_component ⇒ Object (readonly)
Returns the value of attribute rendered_component.
20 21 22 |
# File 'lib/view_component/test_helpers.rb', line 20 def rendered_component @rendered_component end |
Instance Method Details
#controller ⇒ Object
28 29 30 |
# File 'lib/view_component/test_helpers.rb', line 28 def controller @controller ||= Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers) end |
#render_inline(component, **args, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/view_component/test_helpers.rb', line 22 def render_inline(component, **args, &block) @rendered_component = controller.view_context.render(component, args, &block) Nokogiri::HTML.fragment(@rendered_component) end |
#request ⇒ Object
32 33 34 |
# File 'lib/view_component/test_helpers.rb', line 32 def request @request ||= ActionDispatch::TestRequest.create end |
#with_variant(variant) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/view_component/test_helpers.rb', line 36 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 |