code cleanup

This commit is contained in:
Thomas Walpole 2018-01-12 16:57:41 -08:00
parent 0d4d101d98
commit 63a12e7ba0
5 changed files with 37 additions and 64 deletions

View File

@ -174,11 +174,8 @@ module Capybara
#
# @return [Capybara::Node::Element] The option element selected
def select(value = nil, from: nil, **options)
if from
find(:select, from, options).find(:option, value, options).select_option
else
find(:option, value, options).select_option
end
scope = from ? find(:select, from, options) : self
scope.find(:option, value, options).select_option
end
##
@ -196,11 +193,8 @@ module Capybara
#
# @return [Capybara::Node::Element] The option element unselected
def unselect(value = nil, from: nil, **options)
if from
find(:select, from, options).find(:option, value, options).unselect_option
else
find(:option, value, options).unselect_option
end
scope = from ? find(:select, from, options) : self
scope.find(:option, value, options).unselect_option
end
##

View File

@ -115,9 +115,7 @@ module Capybara
def catch_error?(error, errors = nil)
errors ||= (driver.invalid_element_errors + [Capybara::ElementNotFound])
errors.any? do |type|
error.is_a?(type)
end
errors.any? { |type| error.is_a?(type) }
end
def driver

View File

@ -95,10 +95,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def set(value, **options)
raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}" if readonly?
synchronize do
base.set(value, options)
end
synchronize { base.set(value, options) }
self
end
@ -110,7 +107,7 @@ module Capybara
def select_option
warn "Attempt to select disabled option: #{value || text}" if disabled?
synchronize { base.select_option }
return self
self
end
##
@ -120,7 +117,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def unselect_option
synchronize { base.unselect_option }
return self
self
end
##
@ -134,7 +131,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def click(*keys, **offset)
synchronize { base.click(keys, offset) }
return self
self
end
##
@ -145,7 +142,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def right_click(*keys, **offset)
synchronize { base.right_click(keys, offset) }
return self
self
end
##
@ -156,7 +153,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def double_click(*keys, **offset)
synchronize { base.double_click(keys, offset) }
return self
self
end
##
@ -232,7 +229,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def send_keys(*args)
synchronize { base.send_keys(*args) }
return self
self
end
##
@ -242,7 +239,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def hover
synchronize { base.hover }
return self
self
end
##
@ -334,7 +331,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def trigger(event)
synchronize { base.trigger(event) }
return self
self
end
##
@ -350,7 +347,7 @@ module Capybara
# @return [Capybara::Node::Element] The element
def drag_to(node)
synchronize { base.drag_to(node.base) }
return self
self
end
def reload

View File

@ -28,13 +28,9 @@ module Capybara
# @return [Capybara::Node::Element] The found element
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
#
def find(*args, &optional_filter_block)
if args.last.is_a? Hash
args.last[:session_options] = session_options
else
args.push(session_options: session_options)
end
synced_resolve Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
def find(*args, **options, &optional_filter_block)
options[:session_options] = session_options
synced_resolve Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
end
##
@ -57,13 +53,9 @@ module Capybara
# @return [Capybara::Node::Element] The found element
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
#
def ancestor(*args, &optional_filter_block)
if args.last.is_a? Hash
args.last[:session_options] = session_options
else
args.push(session_options: session_options)
end
synced_resolve Capybara::Queries::AncestorQuery.new(*args, &optional_filter_block)
def ancestor(*args, **options, &optional_filter_block)
options[:session_options] = session_options
synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block)
end
##
@ -87,13 +79,9 @@ module Capybara
# @return [Capybara::Node::Element] The found element
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
#
def sibling(*args, &optional_filter_block)
if args.last.is_a? Hash
args.last[:session_options] = session_options
else
args.push(session_options: session_options)
end
synced_resolve Capybara::Queries::SiblingQuery.new(*args, &optional_filter_block)
def sibling(*args, **options, &optional_filter_block)
options[:session_options] = session_options
synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block)
end
##

View File

@ -39,7 +39,7 @@ module Capybara
def has_selector?(*args, &optional_filter_block)
assert_selector(*args, &optional_filter_block)
rescue Capybara::ExpectationNotMet
return false
false
end
##
@ -53,7 +53,7 @@ module Capybara
def has_no_selector?(*args, &optional_filter_block)
assert_no_selector(*args, &optional_filter_block)
rescue Capybara::ExpectationNotMet
return false
false
end
##
@ -637,7 +637,7 @@ module Capybara
def has_text?(*args)
assert_text(*args)
rescue Capybara::ExpectationNotMet
return false
false
end
alias_method :has_content?, :has_text?
@ -651,7 +651,7 @@ module Capybara
def has_no_text?(*args)
assert_no_text(*args)
rescue Capybara::ExpectationNotMet
return false
false
end
alias_method :has_no_content?, :has_no_text?
@ -662,42 +662,38 @@ module Capybara
private
def _verify_selector_result(query_args, optional_filter_block)
_set_query_session_options(query_args)
query_args = _set_query_session_options(*query_args)
query = Capybara::Queries::SelectorQuery.new(*query_args, &optional_filter_block)
synchronize(query.wait) do
result = query.resolve_for(self)
yield result, query
end
return true
true
end
def _verify_match_result(query_args, optional_filter_block)
_set_query_session_options(query_args)
query_args = _set_query_session_options(*query_args)
query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
synchronize(query.wait) do
result = query.resolve_for(query_scope)
yield result
end
return true
true
end
def _verify_text(query_args)
_set_query_session_options(query_args)
query_args = _set_query_session_options(*query_args)
query = Capybara::Queries::TextQuery.new(*query_args)
synchronize(query.wait) do
count = query.resolve_for(self)
yield(count, query)
end
return true
true
end
def _set_query_session_options(query_args)
if query_args.last.is_a? Hash
query_args.last[:session_options] = session_options
else
query_args.push(session_options: session_options)
end
query_args
def _set_query_session_options(*query_args, **query_options)
query_options[:session_options] = session_options
query_args.push(query_options)
end
end
end