Module: ViewComponent::TestHelpers
- Includes:
- Capybara::Minitest::Assertions
- Included in:
- ActionView::Component::TestHelpers, TestCase
- Defined in:
- lib/view_component/test_helpers.rb
Instance Method Summary collapse
- #controller ⇒ Object
- #page ⇒ Object
- #refute_component_rendered ⇒ Object
- #render_inline(component, **args, &block) ⇒ Object
- #request ⇒ Object
- #with_variant(variant) ⇒ Object
Instance Method Details
#controller ⇒ Object
23 24 25 |
# File 'lib/view_component/test_helpers.rb', line 23 def controller @controller ||= Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers) end |
#page ⇒ Object
9 10 11 |
# File 'lib/view_component/test_helpers.rb', line 9 def page Capybara::Node::Simple.new(@raw) end |
#refute_component_rendered ⇒ Object
13 14 15 |
# File 'lib/view_component/test_helpers.rb', line 13 def refute_component_rendered assert_no_selector("body") end |
#render_inline(component, **args, &block) ⇒ Object
17 18 19 20 21 |
# File 'lib/view_component/test_helpers.rb', line 17 def render_inline(component, **args, &block) @raw = controller.view_context.render(component, args, &block) Nokogiri::HTML.fragment(@raw) end |
#request ⇒ Object
27 28 29 |
# File 'lib/view_component/test_helpers.rb', line 27 def request @request ||= ActionDispatch::TestRequest.create end |
#with_variant(variant) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/view_component/test_helpers.rb', line 31 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 |