Skip to content

Commit

Permalink
Implementation for issue teamcapybara#1319 - propagate fill_in option…
Browse files Browse the repository at this point in the history
…s to Element#set
  • Loading branch information
twalpole committed Jun 19, 2014
1 parent 6ba0c70 commit 2ce3669
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/capybara/driver/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def value
end

# @param value String or Array. Array is only allowed if node has 'multiple' attribute
def set(value)
# @param options [Hash{}] Driver specific options for how to set a value on a node
def set(value, options={})
raise NotImplementedError
end

Expand Down
7 changes: 5 additions & 2 deletions lib/capybara/node/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ def click_button(locator, options={})
# page.fill_in 'Name', :with => 'Bob'
#
# @param [String] locator Which field to fill in
# @param [Hash{:with => String}] options The value to fill in
# @param [Hash] options
# @option options [String] :with The value to fill in - required
# @option options [Hash] :fill_options Driver specific options regarding how to fill fields
#
def fill_in(locator, options={})
raise "Must pass a hash containing 'with'" if not options.is_a?(Hash) or not options.has_key?(:with)
with = options.delete(:with)
find(:fillable_field, locator, options).set(with)
fill_options = options.delete(:fill_options)
find(:fillable_field, locator, options).set(with, fill_options)
end

##
Expand Down
19 changes: 17 additions & 2 deletions lib/capybara/node/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,24 @@ def value
# Set the value of the form element to the given value.
#
# @param [String] value The new value
# @param [Hash{}] options Driver specific options for how to set the value
#
def set(value)
synchronize { base.set(value) }
def set(value, options={})
options ||= {}

driver_supports_options = (base.method(:set).arity != 1)

unless options.empty? || driver_supports_options
warn "Options passed to Capybara::Node#set but the driver doesn't support them"
end

synchronize do
if driver_supports_options
base.set(value, options)
else
base.set(value)
end
end
end

##
Expand Down

0 comments on commit 2ce3669

Please sign in to comment.