Module: Capybara::UI::Widgets::DSL

Included in:
Role, Capybara::UI::Widget
Defined in:
lib/capybara/ui/widgets/dsl.rb

Instance Method Summary collapse

Instance Method Details

#form(name, *rest, &block) ⇒ Object

Declares a new form widget.

See features/role.feature.


8
9
10
# File 'lib/capybara/ui/widgets/dsl.rb', line 8

def form(name, *rest, &block)
  widget name, *rest, Capybara::UI::Form, &block
end

#list(name, *rest, &block) ⇒ Object

Declares a new list widget.

See features/roles/list.feature.


15
16
17
# File 'lib/capybara/ui/widgets/dsl.rb', line 15

def list(name, *rest, &block)
  widget name, *rest, Capybara::UI::List, &block
end

#widget(name, selector_or_parent, parent = Widget, &block) ⇒ Object

Raises:

  • (ArgumentError)

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/capybara/ui/widgets/dsl.rb', line 22

def widget(name, selector_or_parent, parent = Widget, &block)
  raise ArgumentError, "`#{name}' is a reserved name" \
    if WidgetParts::Container.instance_methods.include?(name.to_sym)

  case selector_or_parent
  when String, Array, Proc
    selector, type = selector_or_parent, parent
  when Class
    selector, type = selector_or_parent.selector, selector_or_parent
  else
    raise ArgumentError, "wrong number of arguments (#{rest.size} for 1)"
  end

  raise TypeError, "can't convert `#{type}' to Widget" \
    unless type.methods.include?(:selector)

  raise ArgumentError, "missing selector" unless selector || type.selector

  child = WidgetClass.new(selector, type, &block)

  const_set(Capybara::UI::WidgetName.new(name).to_sym, child)

  child
end