Module: Dill::DSL

Included in:
Role
Defined in:
lib/dill/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#widget_lookup_scopeObject



81
82
83
# File 'lib/dill/dsl.rb', line 81

def widget_lookup_scope
  @widget_lookup_scope ||= default_widget_lookup_scope
end

Instance Method Details

#click(name, *args) ⇒ Object

Clicks the widget defined by name and optional args.

Makes no distinction between links or buttons.

class MyWidget < Dill::Widget
  root { |text| ['.my-widget', text: text] }
end

#  <a href="#one" class="my-widget">One</li>
#  <a href="#two" class="my-widget">Two</li> <!-- clicks this node -->
click :my_widget, 'Two'


16
17
18
# File 'lib/dill/dsl.rb', line 16

def click(name, *args)
  widget(name, *args).click
end

#documentDocument

Returns the current document with the class of the current object set as the widget lookup scope.

Returns:

  • (Document)

    the current document with the class of the current object set as the widget lookup scope.



27
28
29
# File 'lib/dill/dsl.rb', line 27

def document
  Document.new(widget_lookup_scope)
end

#eventually(wait_time = Capybara.default_max_wait_time, &block) ⇒ Object

re-run one or more assertions until either they all pass, or Dill times out, which will result in a test failure.



87
88
89
# File 'lib/dill/dsl.rb', line 87

def eventually(wait_time = Capybara.default_max_wait_time, &block)
  Checkpoint.wait_for wait_time, &block
end

#has_widget?(name, *args) ⇒ Boolean Also known as: widget?

Returns Whether one or more widgets exist in the current document.

Returns:

  • (Boolean)

    Whether one or more widgets exist in the current document.



33
34
35
# File 'lib/dill/dsl.rb', line 33

def has_widget?(name, *args)
  document.has_widget?(name, *args)
end

#hover(name, *args) ⇒ Object

Hovers the widget defined by name and optional args.



21
22
23
# File 'lib/dill/dsl.rb', line 21

def hover(name, *args)
  widget(name, *args).hover
end

#not_visible?(name, *args) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/dill/dsl.rb', line 43

def not_visible?(name, *args)
  document.not_visible?(name, *args)
end

#set(name, fields) ⇒ Object



47
48
49
# File 'lib/dill/dsl.rb', line 47

def set(name, fields)
  widget(name).set fields
end

#submit(name, fields = {}) ⇒ Object



51
52
53
# File 'lib/dill/dsl.rb', line 51

def submit(name, fields = {})
  widget(name).submit_with fields
end

#value(name, *args) ⇒ Object



55
56
57
# File 'lib/dill/dsl.rb', line 55

def value(name, *args)
  widget(name, *args).value
end

#values(name, *args) ⇒ Object



59
60
61
# File 'lib/dill/dsl.rb', line 59

def values(name, *args)
  widgets(name, *args).map(&:value)
end

#visible?(name, *args) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/dill/dsl.rb', line 39

def visible?(name, *args)
  document.visible?(name, *args)
end

#visit(path) ⇒ Object



63
64
65
# File 'lib/dill/dsl.rb', line 63

def visit(path)
  Capybara.current_session.visit path
end

#widget(name, *args) ⇒ Object

Returns a widget instance for the given name.

Parameters:



70
71
72
# File 'lib/dill/dsl.rb', line 70

def widget(name, *args)
  eventually { document.widget(name, *args) }
end

#widgets(name, *args) ⇒ Object

Returns a list of widget instances for the given name.

Parameters:



77
78
79
# File 'lib/dill/dsl.rb', line 77

def widgets(name, *args)
  document.widgets(name, *args)
end