diff --git a/lib/capybara/queries/current_path_query.rb b/lib/capybara/queries/current_path_query.rb index 46097241..68264cc6 100644 --- a/lib/capybara/queries/current_path_query.rb +++ b/lib/capybara/queries/current_path_query.rb @@ -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 diff --git a/lib/capybara/selector/builders/css_builder.rb b/lib/capybara/selector/builders/css_builder.rb index 7ee3256a..7cc0656c 100644 --- a/lib/capybara/selector/builders/css_builder.rb +++ b/lib/capybara/selector/builders/css_builder.rb @@ -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 diff --git a/lib/capybara/selector/builders/xpath_builder.rb b/lib/capybara/selector/builders/xpath_builder.rb index b55ad9fe..61baba34 100644 --- a/lib/capybara/selector/builders/xpath_builder.rb +++ b/lib/capybara/selector/builders/xpath_builder.rb @@ -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 diff --git a/lib/capybara/selector/definition.rb b/lib/capybara/selector/definition.rb index d3a58e94..ab905d84 100644 --- a/lib/capybara/selector/definition.rb +++ b/lib/capybara/selector/definition.rb @@ -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) diff --git a/lib/capybara/selector/filter_set.rb b/lib/capybara/selector/filter_set.rb index 56962a9a..cd6a04ec 100644 --- a/lib/capybara/selector/filter_set.rb +++ b/lib/capybara/selector/filter_set.rb @@ -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) diff --git a/lib/capybara/selenium/driver_specializations/chrome_driver.rb b/lib/capybara/selenium/driver_specializations/chrome_driver.rb index 62912cc1..cdef8399 100644 --- a/lib/capybara/selenium/driver_specializations/chrome_driver.rb +++ b/lib/capybara/selenium/driver_specializations/chrome_driver.rb @@ -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) diff --git a/lib/capybara/selenium/driver_specializations/edge_driver.rb b/lib/capybara/selenium/driver_specializations/edge_driver.rb index ec38432b..8e1dbd7a 100644 --- a/lib/capybara/selenium/driver_specializations/edge_driver.rb +++ b/lib/capybara/selenium/driver_specializations/edge_driver.rb @@ -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 diff --git a/lib/capybara/selenium/driver_specializations/firefox_driver.rb b/lib/capybara/selenium/driver_specializations/firefox_driver.rb index 1ef21f8b..a2ceb304 100644 --- a/lib/capybara/selenium/driver_specializations/firefox_driver.rb +++ b/lib/capybara/selenium/driver_specializations/firefox_driver.rb @@ -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 diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index 48da8d62..d31f8927 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -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 diff --git a/lib/capybara/selenium/nodes/safari_node.rb b/lib/capybara/selenium/nodes/safari_node.rb index a5b02494..84d560ef 100644 --- a/lib/capybara/selenium/nodes/safari_node.rb +++ b/lib/capybara/selenium/nodes/safari_node.rb @@ -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 diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index e93964ac..b95f96c6 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -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