Class: ViewComponent::CapybaraSimpleSession

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(html) ⇒ CapybaraSimpleSession

Initializes the receiver with the given string of HTML.

Parameters:

  • html (String)

    the HTML to create the session out of



87
88
89
# File 'lib/view_component/capybara_simple_session.rb', line 87

def initialize(html)
  @document = Capybara::Node::Simple.new(html)
end

Instance Method Details

#nativeObject



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.to_capybara_node : 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