Class: Capybara::Harness::Dom::Field
- Inherits:
-
Object
- Object
- Capybara::Harness::Dom::Field
- Includes:
- DSL
- Defined in:
- lib/capybara/harness/dom/field.rb
Instance Attribute Summary collapse
-
#as ⇒ Object
Returns the value of attribute as.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#through ⇒ Object
Returns the value of attribute through.
Instance Method Summary collapse
- #fill(attrs = {}) ⇒ Object
-
#initialize(name, options = {}) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(name, options = {}) ⇒ Field
Returns a new instance of Field.
7 8 9 10 11 12 |
# File 'lib/capybara/harness/dom/field.rb', line 7 def initialize(name, = {}) @name = name.to_sym @through = extract_option_as_sym(:through, ) @label = .fetch(:label, name.to_s.humanize) @as = .fetch(:as, :string).to_sym end |
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as.
5 6 7 |
# File 'lib/capybara/harness/dom/field.rb', line 5 def as @as end |
#label ⇒ Object
Returns the value of attribute label.
5 6 7 |
# File 'lib/capybara/harness/dom/field.rb', line 5 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/capybara/harness/dom/field.rb', line 5 def name @name end |
#through ⇒ Object
Returns the value of attribute through.
5 6 7 |
# File 'lib/capybara/harness/dom/field.rb', line 5 def through @through end |
Instance Method Details
#fill(attrs = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/capybara/harness/dom/field.rb', line 14 def fill(attrs = {}) value = extract_value(attrs) case as when :string then fill_in(label, :with => value) when :select then select(value, :from => label) when :file attach_file(label, value) when :radio choose(label) when :checkbox, :checkboxes if value.is_a?(Hash) value.each { |label, v| checkbox(v, label) } elsif value.is_a?(Array) value.each { |v| checkbox(v) } else check(value, label) end end end |