lib/capybara/node/finders.rb in capybara-3.1.1 vs lib/capybara/node/finders.rb in capybara-3.2.0
- old
+ new
@@ -53,11 +53,11 @@
# @return [Capybara::Node::Element] The found element
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
#
def ancestor(*args, **options, &optional_filter_block)
options[:session_options] = session_options
- synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block)
+ synced_resolve Capybara::Queries::AncestorQuery.new(*args, options, &optional_filter_block)
end
##
#
# Find an {Capybara::Node::Element} based on the given arguments that is also a sibling of the element called on. +sibling+ will raise an error if the element
@@ -79,18 +79,18 @@
# @return [Capybara::Node::Element] The found element
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
#
def sibling(*args, **options, &optional_filter_block)
options[:session_options] = session_options
- synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block)
+ synced_resolve Capybara::Queries::SiblingQuery.new(*args, options, &optional_filter_block)
end
##
#
# Find a form field on the page. The field can be found by its name, id or label text.
#
- # @overload find_field([locator], options={})
+ # @overload find_field([locator], **options)
# @param [String] locator name, id, placeholder or text of associated label element
#
# @macro waiting_behavior
#
#
@@ -117,11 +117,11 @@
##
#
# Find a link on the page. The link can be found by its id or text.
#
- # @overload find_link([locator], options={})
+ # @overload find_link([locator], **options)
# @param [String] locator id, title, text, or alt of enclosed img element
#
# @macro waiting_behavior
#
# @option options [String,Regexp,nil] href Value to match against the links href, if nil finds link placeholders (<a> elements with no href attribute)
@@ -140,14 +140,14 @@
# Find a button on the page.
# This can be any \<input> element of type submit, reset, image, button or it can be a
# \<button> element. All buttons can be found by their id, value, or title. \<button> elements can also be found
# by their text content, and image \<input> elements by their alt attribute
#
- # @overload find_button([locator], options={})
+ # @overload find_button([locator], **options)
# @param [String] locator id, value, title, text content, alt of image
#
- # @overload find_button(options={})
+ # @overload find_button(**options)
#
# @macro waiting_behavior
#
# @option options [Boolean, Symbol] disabled (false) Match disabled button?
# * true - only finds a disabled button
@@ -176,11 +176,11 @@
def find_by_id(id, **options, &optional_filter_block)
find(:id, id, options, &optional_filter_block)
end
##
- # @!method all([kind = Capybara.default_selector], locator = nil, options = {})
+ # @!method all([kind = Capybara.default_selector], locator = nil, **options)
#
# Find all elements on the page matching the given selector
# and options.
#
# Both XPath and CSS expressions are supported, but Capybara
@@ -233,21 +233,21 @@
# @option options [Integer] maximum Maximum number of matches that are expected to be found
# @option options [Integer] minimum Minimum number of matches that are expected to be found
# @option options [Range] between Number of matches found must be within the given range
# @option options [Boolean] exact Control whether `is` expressions in the given XPath match exactly or partially
# @option options [Integer, false] wait (Capybara.default_max_wait_time) The time to wait for matching elements to become available
- # @overload all([kind = Capybara.default_selector], locator = nil, options = {})
- # @overload all([kind = Capybara.default_selector], locator = nil, options = {}, &filter_block)
+ # @overload all([kind = Capybara.default_selector], locator = nil, **options)
+ # @overload all([kind = Capybara.default_selector], locator = nil, **options, &filter_block)
# @yieldparam element [Capybara::Node::Element] The element being considered for inclusion in the results
# @yieldreturn [Boolean] Should the element be considered in the results?
# @return [Capybara::Result] A collection of found elements
# @raise [Capybara::ExpectationNotMet] The number of elements found doesn't match the specified conditions
def all(*args, **options, &optional_filter_block)
minimum_specified = options_include_minimum?(options)
options = { minimum: 1 }.merge(options) unless minimum_specified
options[:session_options] = session_options
- query = Capybara::Queries::SelectorQuery.new(*args.push(options), &optional_filter_block)
+ query = Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
result = nil
begin
synchronize(query.wait) do
result = query.resolve_for(self)
raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
@@ -274,11 +274,11 @@
# @return [Capybara::Node::Element] The found element or nil
# @raise [Capybara::ElementNotFound] If element(s) matching the provided options can't be found before time expires
#
def first(*args, **options, &optional_filter_block)
options = { minimum: 1 }.merge(options) unless options_include_minimum?(options)
- all(*args, **options, &optional_filter_block).first
+ all(*args, options, &optional_filter_block).first
end
private
def synced_resolve(query)
@@ -296,14 +296,14 @@
result.first
end.tap(&:allow_reload!)
end
def ambiguous?(query, result)
- query.match == :one or query.match == :smart and result.size > 1
+ %i[one smart].include?(query.match) && (result.size > 1)
end
def prefer_exact?(query)
- query.match == :smart or query.match == :prefer_exact
+ %i[smart prefer_exact].include?(query.match)
end
def options_include_minimum?(opts)
%i[count minimum between].any? { |k| opts.key?(k) }
end