Class: ViewComponent::CapybaraSimpleSession
- Inherits:
-
Object
- Object
- ViewComponent::CapybaraSimpleSession
- Defined in:
- lib/view_component/capybara_simple_session.rb
Overview
This is a simpler version of Capybara::Session.
It only includes Capybara::Node::Finders, Capybara::Node::Matchers, #within and #within_element. It is useful in that it does not require a session, an application or a driver, but can still use Capybara’s finders and matchers on any string that contains HTML.
Constant Summary collapse
- DSL_METHODS =
(NODE_METHODS + SESSION_METHODS).freeze
Instance Method Summary collapse
-
#initialize(html) ⇒ CapybaraSimpleSession
constructor
Initializes the receiver with the given string of HTML.
- #native ⇒ Object
- #within(*args, **kw_args) ⇒ Object (also: #within_element)
- #within_fieldset(locator, &block) ⇒ Object
- #within_table(locator, &block) ⇒ Object
Constructor Details
#initialize(html) ⇒ CapybaraSimpleSession
Initializes the receiver with the given string of HTML.
87 88 89 |
# File 'lib/view_component/capybara_simple_session.rb', line 87 def initialize(html) @document = ::Node::Simple.new(html) end |
Instance Method Details
#native ⇒ Object
116 117 118 |
# File 'lib/view_component/capybara_simple_session.rb', line 116 def native current_scope.native end |
#within(*args, **kw_args) ⇒ Object Also known as: within_element
92 93 94 95 96 97 98 99 100 |
# File 'lib/view_component/capybara_simple_session.rb', line 92 def within(*args, **kw_args) new_scope = args.first.respond_to?(:to_capybara_node) ? args.first. : find(*args, **kw_args) begin scopes.push(new_scope) yield if block_given? ensure scopes.pop end end |
#within_fieldset(locator, &block) ⇒ Object
106 107 108 |
# File 'lib/view_component/capybara_simple_session.rb', line 106 def within_fieldset(locator, &block) within(:fieldset, locator, &block) end |
#within_table(locator, &block) ⇒ Object
111 112 113 |
# File 'lib/view_component/capybara_simple_session.rb', line 111 def within_table(locator, &block) within(:table, locator, &block) end |