Module: ActionView::Component::TestHelpers
- Includes:
- Capybara::Minitest::Assertions
- Included in:
- TestCase
- Defined in:
- lib/action_view/component/test_helpers.rb
Instance Method Summary collapse
- #controller ⇒ Object
- #page ⇒ Object
- #render_component(component, **args, &block) ⇒ Object
- #render_inline(component, **args, &block) ⇒ Object
- #request ⇒ Object
- #with_variant(variant) ⇒ Object
Instance Method Details
#controller ⇒ Object
20 21 22 |
# File 'lib/action_view/component/test_helpers.rb', line 20 def controller @controller ||= Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers) end |
#page ⇒ Object
10 11 12 |
# File 'lib/action_view/component/test_helpers.rb', line 10 def page Capybara::Node::Simple.new(@raw) end |
#render_component(component, **args, &block) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/action_view/component/test_helpers.rb', line 28 def render_component(component, **args, &block) ActiveSupport::Deprecation.warn( "`render_component` has been deprecated in favor of `render_inline`, and will be removed in v2.0.0." ) render_inline(component, args, &block) end |
#render_inline(component, **args, &block) ⇒ Object
14 15 16 17 18 |
# File 'lib/action_view/component/test_helpers.rb', line 14 def render_inline(component, **args, &block) @raw = controller.view_context.render(component, args, &block) Nokogiri::HTML.fragment(@raw) end |
#request ⇒ Object
24 25 26 |
# File 'lib/action_view/component/test_helpers.rb', line 24 def request @request ||= ActionDispatch::TestRequest.create end |
#with_variant(variant) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/action_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 |