mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
code cleanup
This commit is contained in:
parent
b6752b1259
commit
705e49ad56
11 changed files with 16 additions and 17 deletions
|
@ -19,7 +19,7 @@ module Capybara
|
|||
|
||||
def resolves_for?(session)
|
||||
uri = ::Addressable::URI.parse(session.current_url)
|
||||
@actual_path = (options[:ignore_query] ? uri&.omit(:query) : uri).yield_self do |u|
|
||||
@actual_path = (options[:ignore_query] ? uri&.omit(:query) : uri).then do |u|
|
||||
options[:url] ? u&.to_s : u&.request_uri
|
||||
end
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ module Capybara
|
|||
else
|
||||
cls = Array(classes).reject { |c| c.is_a? Regexp }.group_by { |cl| cl.match?(/^!(?!!!)/) }
|
||||
[(cls[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl.sub(/^!!/, ''))}" } +
|
||||
cls[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1..-1))})" }).join]
|
||||
cls[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1..))})" }).join]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ module Capybara
|
|||
else
|
||||
Array(classes).reject { |c| c.is_a? Regexp }.map do |klass|
|
||||
if klass.match?(/^!(?!!!)/)
|
||||
!XPath.attr(:class).contains_word(klass.slice(1..-1))
|
||||
!XPath.attr(:class).contains_word(klass.slice(1..))
|
||||
else
|
||||
XPath.attr(:class).contains_word(klass.sub(/^!!/, ''))
|
||||
end
|
||||
|
|
|
@ -260,7 +260,8 @@ module Capybara
|
|||
|
||||
def parameter_names(block)
|
||||
key_types = %i[key keyreq]
|
||||
block.parameters.select { |(type, _name)| key_types.include? type }.map { |(_type, name)| name }
|
||||
# user filter_map when we drop dupport for 2.6
|
||||
block.parameters.select { |(type, _name)| key_types.include? type }.map { |(_, name)| name }
|
||||
end
|
||||
|
||||
def expression(type, allowed_filters, &block)
|
||||
|
|
|
@ -101,13 +101,11 @@ module Capybara
|
|||
private
|
||||
|
||||
def options_with_defaults(options)
|
||||
options = options.dup
|
||||
[expression_filters, node_filters].each do |filters|
|
||||
filters.select { |_n, filter| filter.default? }.each do |name, filter|
|
||||
options[name] = filter.default unless options.key?(name)
|
||||
end
|
||||
expression_filters.chain(node_filters)
|
||||
.select { |_n, filter| filter.default? }
|
||||
.each_with_object(options.dup) do |(name, filter), opts|
|
||||
opts[name] = filter.default unless opts.key?(name)
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
def add_filter(name, filter_class, *types, matcher: nil, **options, &block)
|
||||
|
|
|
@ -38,7 +38,7 @@ module Capybara::Selenium::Driver::ChromeDriver
|
|||
return unless @browser
|
||||
|
||||
switch_to_window(window_handles.first)
|
||||
window_handles.slice(1..-1).each { |win| close_window(win) }
|
||||
window_handles.slice(1..).each { |win| close_window(win) }
|
||||
return super if chromedriver_version < 73
|
||||
|
||||
timer = Capybara::Helpers.timer(expire_in: 10)
|
||||
|
|
|
@ -39,7 +39,7 @@ module Capybara::Selenium::Driver::EdgeDriver
|
|||
return unless @browser
|
||||
|
||||
switch_to_window(window_handles.first)
|
||||
window_handles.slice(1..-1).each { |win| close_window(win) }
|
||||
window_handles.slice(1..).each { |win| close_window(win) }
|
||||
|
||||
timer = Capybara::Helpers.timer(expire_in: 10)
|
||||
begin
|
||||
|
|
|
@ -52,7 +52,7 @@ module Capybara::Selenium::Driver::W3CFirefoxDriver
|
|||
end
|
||||
|
||||
switch_to_window(window_handles.first)
|
||||
window_handles.slice(1..-1).each { |win| close_window(win) }
|
||||
window_handles.slice(1..).each { |win| close_window(win) }
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ private
|
|||
elsif clear == :backspace
|
||||
# Clear field by sending the correct number of backspace keys.
|
||||
backspaces = [:backspace] * self.value.to_s.length
|
||||
send_keys(*([:end] + backspaces + [value]))
|
||||
send_keys(:end, *backspaces, value)
|
||||
elsif clear.is_a? Array
|
||||
send_keys(*clear, value)
|
||||
else
|
||||
|
|
|
@ -74,7 +74,7 @@ class Capybara::Selenium::SafariNode < Capybara::Selenium::Node
|
|||
if clear == :backspace
|
||||
# Clear field by sending the correct number of backspace keys.
|
||||
backspaces = [:backspace] * self.value.to_s.length
|
||||
send_keys(*([[:control, 'e']] + backspaces + [value]))
|
||||
send_keys([:control, 'e'], *backspaces, value)
|
||||
else
|
||||
super.tap do
|
||||
# React doesn't see the safaridriver element clear
|
||||
|
|
|
@ -408,11 +408,11 @@ module Capybara
|
|||
idx = scopes.index(:frame)
|
||||
top_level_scopes = [:frame, nil]
|
||||
if idx
|
||||
if scopes.slice(idx..-1).any? { |scope| !top_level_scopes.include?(scope) }
|
||||
if scopes.slice(idx..).any? { |scope| !top_level_scopes.include?(scope) }
|
||||
raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's "\
|
||||
'`within` block.'
|
||||
end
|
||||
scopes.slice!(idx..-1)
|
||||
scopes.slice!(idx..)
|
||||
driver.switch_to_frame(:top)
|
||||
end
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue