1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

code cleanup

This commit is contained in:
Thomas Walpole 2021-03-27 21:35:21 -07:00
parent b6752b1259
commit 705e49ad56
11 changed files with 16 additions and 17 deletions

View file

@ -19,7 +19,7 @@ module Capybara
def resolves_for?(session) def resolves_for?(session)
uri = ::Addressable::URI.parse(session.current_url) 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 options[:url] ? u&.to_s : u&.request_uri
end end

View file

@ -76,7 +76,7 @@ module Capybara
else else
cls = Array(classes).reject { |c| c.is_a? Regexp }.group_by { |cl| cl.match?(/^!(?!!!)/) } 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[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 end
end end

View file

@ -51,7 +51,7 @@ module Capybara
else else
Array(classes).reject { |c| c.is_a? Regexp }.map do |klass| Array(classes).reject { |c| c.is_a? Regexp }.map do |klass|
if klass.match?(/^!(?!!!)/) if klass.match?(/^!(?!!!)/)
!XPath.attr(:class).contains_word(klass.slice(1..-1)) !XPath.attr(:class).contains_word(klass.slice(1..))
else else
XPath.attr(:class).contains_word(klass.sub(/^!!/, '')) XPath.attr(:class).contains_word(klass.sub(/^!!/, ''))
end end

View file

@ -260,7 +260,8 @@ module Capybara
def parameter_names(block) def parameter_names(block)
key_types = %i[key keyreq] 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 end
def expression(type, allowed_filters, &block) def expression(type, allowed_filters, &block)

View file

@ -101,13 +101,11 @@ module Capybara
private private
def options_with_defaults(options) def options_with_defaults(options)
options = options.dup expression_filters.chain(node_filters)
[expression_filters, node_filters].each do |filters| .select { |_n, filter| filter.default? }
filters.select { |_n, filter| filter.default? }.each do |name, filter| .each_with_object(options.dup) do |(name, filter), opts|
options[name] = filter.default unless options.key?(name) opts[name] = filter.default unless opts.key?(name)
end
end end
options
end end
def add_filter(name, filter_class, *types, matcher: nil, **options, &block) def add_filter(name, filter_class, *types, matcher: nil, **options, &block)

View file

@ -38,7 +38,7 @@ module Capybara::Selenium::Driver::ChromeDriver
return unless @browser return unless @browser
switch_to_window(window_handles.first) 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 return super if chromedriver_version < 73
timer = Capybara::Helpers.timer(expire_in: 10) timer = Capybara::Helpers.timer(expire_in: 10)

View file

@ -39,7 +39,7 @@ module Capybara::Selenium::Driver::EdgeDriver
return unless @browser return unless @browser
switch_to_window(window_handles.first) 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) timer = Capybara::Helpers.timer(expire_in: 10)
begin begin

View file

@ -52,7 +52,7 @@ module Capybara::Selenium::Driver::W3CFirefoxDriver
end end
switch_to_window(window_handles.first) 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 super
end end

View file

@ -274,7 +274,7 @@ private
elsif clear == :backspace elsif clear == :backspace
# Clear field by sending the correct number of backspace keys. # Clear field by sending the correct number of backspace keys.
backspaces = [:backspace] * self.value.to_s.length backspaces = [:backspace] * self.value.to_s.length
send_keys(*([:end] + backspaces + [value])) send_keys(:end, *backspaces, value)
elsif clear.is_a? Array elsif clear.is_a? Array
send_keys(*clear, value) send_keys(*clear, value)
else else

View file

@ -74,7 +74,7 @@ class Capybara::Selenium::SafariNode < Capybara::Selenium::Node
if clear == :backspace if clear == :backspace
# Clear field by sending the correct number of backspace keys. # Clear field by sending the correct number of backspace keys.
backspaces = [:backspace] * self.value.to_s.length backspaces = [:backspace] * self.value.to_s.length
send_keys(*([[:control, 'e']] + backspaces + [value])) send_keys([:control, 'e'], *backspaces, value)
else else
super.tap do super.tap do
# React doesn't see the safaridriver element clear # React doesn't see the safaridriver element clear

View file

@ -408,11 +408,11 @@ module Capybara
idx = scopes.index(:frame) idx = scopes.index(:frame)
top_level_scopes = [:frame, nil] top_level_scopes = [:frame, nil]
if idx 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 "\ raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's "\
'`within` block.' '`within` block.'
end end
scopes.slice!(idx..-1) scopes.slice!(idx..)
driver.switch_to_frame(:top) driver.switch_to_frame(:top)
end end
else else