Class: Capybara::Harness::Dom::Field

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/capybara/harness/dom/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @name = name.to_sym
  @through = extract_option_as_sym(:through, options)
  @label = options.fetch(:label, name.to_s.humanize)
  @as = options.fetch(:as, :string).to_sym
end

Instance Attribute Details

#asObject

Returns the value of attribute as.



5
6
7
# File 'lib/capybara/harness/dom/field.rb', line 5

def as
  @as
end

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/capybara/harness/dom/field.rb', line 5

def label
  @label
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/capybara/harness/dom/field.rb', line 5

def name
  @name
end

#throughObject

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