Module: Cucumber::Salad::WidgetMacros
- Included in:
- Cucumber::Salad::Widgets::Widget
- Defined in:
- lib/cucumber/salad/widget_macros.rb
Instance Method Summary collapse
-
#action(name, selector) ⇒ Object
Defines a new action.
-
#widget(name, selector, parent = Widgets::Widget) { ... } ⇒ Object
Declares a new sub-widget.
-
#widget_delegator(name, widget_message, method_name = nil) ⇒ Object
Creates a delegator for one sub-widget message.
Instance Method Details
#action(name, selector) ⇒ Object
Defines a new action.
This is a shortcut to help defining a widget and a method that clicks on that widget. You can then send a widget instance the message given by name
.
28 29 30 31 32 33 34 35 36 |
# File 'lib/cucumber/salad/widget_macros.rb', line 28 def action(name, selector) name, selector define_method name do (name).click self end end |
#widget(name, selector, parent = Widgets::Widget) { ... } ⇒ Object
Declares a new sub-widget.
Sub-widgets are accessible inside the container widget using the widget
message.
50 51 52 53 54 55 56 57 58 |
# File 'lib/cucumber/salad/widget_macros.rb', line 50 def (name, selector, parent = Widgets::Widget, &block) type = Class.new(parent) { root selector instance_eval(&block) if block } const_set(Salad::WidgetName.new(name).to_sym, type) end |
#widget_delegator(name, widget_message, method_name = nil) ⇒ Object
Creates a delegator for one sub-widget message.
Since widgets are accessed through Cucumber::Salad::WidgetContainer#widget, we can’t use Forwardable to delegate messages to widgets.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cucumber/salad/widget_macros.rb', line 69 def (name, , method_name = nil) method_name = method_name || class_eval <<-RUBY def #{method_name}(*args) if args.size == 1 widget(:#{name}).#{} args.first else widget(:#{name}).#{} *args end end RUBY end |