diff --git a/.rubocop.yml b/.rubocop.yml index 58290308fd..863f5c5f27 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,7 +8,7 @@ require: AllCops: NewCops: enable DisabledByDefault: false - TargetRubyVersion: 3.0 + TargetRubyVersion: 3.1 Exclude: - 'vendor/**/*' - 'gemfiles/vendor/**/*' diff --git a/capybara.gemspec b/capybara.gemspec index d33aac37dc..59074c037a 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -8,7 +8,7 @@ require 'capybara/version' Gem::Specification.new do |s| s.name = 'capybara' s.version = Capybara::VERSION - s.required_ruby_version = '>= 3.0.0' + s.required_ruby_version = '>= 3.1.0' s.license = 'MIT' s.authors = ['Thomas Walpole', 'Jonas Nicklas'] diff --git a/lib/capybara.rb b/lib/capybara.rb index 41c9b5f735..20612169f2 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -179,8 +179,8 @@ def register_server(name, &block) # @param [Symbol] name The name of the selector to add # @yield A block executed in the context of the new {Capybara::Selector} # - def add_selector(name, **options, &block) - Capybara::Selector.add(name, **options, &block) + def add_selector(name, **options, &) + Capybara::Selector.add(name, **options, &) end ## @@ -197,8 +197,8 @@ def add_selector(name, **options, &block) # @param [Symbol] name The name of the selector to modify # @yield A block executed in the context of the existing {Capybara::Selector} # - def modify_selector(name, &block) - Capybara::Selector.update(name, &block) + def modify_selector(name, &) + Capybara::Selector.update(name, &) end def drivers @@ -358,10 +358,10 @@ def session_name=(name) def using_session(name_or_session, &block) previous_session = current_session previous_session_info = { - specified_session: specified_session, - session_name: session_name, - current_driver: current_driver, - app: app + specified_session:, + session_name:, + current_driver:, + app: } self.specified_session = self.session_name = nil if name_or_session.is_a? Capybara::Session diff --git a/lib/capybara/driver/base.rb b/lib/capybara/driver/base.rb index 997463776d..17953719f4 100644 --- a/lib/capybara/driver/base.rb +++ b/lib/capybara/driver/base.rb @@ -135,7 +135,7 @@ def no_such_window_error # @return [String] the message shown in the modal # @raise [Capybara::ModalNotFound] if modal dialog hasn't been found # - def accept_modal(type, **options, &blk) + def accept_modal(type, **options, &) raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#accept_modal' end @@ -148,7 +148,7 @@ def accept_modal(type, **options, &blk) # @return [String] the message shown in the modal # @raise [Capybara::ModalNotFound] if modal dialog hasn't been found # - def dismiss_modal(type, **options, &blk) + def dismiss_modal(type, **options, &) raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#dismiss_modal' end diff --git a/lib/capybara/dsl.rb b/lib/capybara/dsl.rb index 14066d4965..d8a633e202 100644 --- a/lib/capybara/dsl.rb +++ b/lib/capybara/dsl.rb @@ -18,14 +18,14 @@ def self.extended(base) # # Shortcut to working in a different session. # - def using_session(name_or_session, &block) - Capybara.using_session(name_or_session, &block) + def using_session(name_or_session, &) + Capybara.using_session(name_or_session, &) end # Shortcut to using a different wait time. # - def using_wait_time(seconds, &block) - page.using_wait_time(seconds, &block) + def using_wait_time(seconds, &) + page.using_wait_time(seconds, &) end ## diff --git a/lib/capybara/helpers.rb b/lib/capybara/helpers.rb index 90ab6f211a..8f887c5bee 100644 --- a/lib/capybara/helpers.rb +++ b/lib/capybara/helpers.rb @@ -82,7 +82,7 @@ def filter_backtrace(trace) end def warn(message, uplevel: 1) - Kernel.warn(message, uplevel: uplevel) + Kernel.warn(message, uplevel:) end if defined?(Process::CLOCK_MONOTONIC_RAW) diff --git a/lib/capybara/node/document.rb b/lib/capybara/node/document.rb index 16e151edcf..624fc0087f 100644 --- a/lib/capybara/node/document.rb +++ b/lib/capybara/node/document.rb @@ -21,7 +21,7 @@ def inspect # @return [String] The text of the document # def text(type = nil, normalize_ws: false) - find(:xpath, '/html').text(type, normalize_ws: normalize_ws) + find(:xpath, '/html').text(type, normalize_ws:) end ## diff --git a/lib/capybara/node/finders.rb b/lib/capybara/node/finders.rb index d932eb4313..680532f3fb 100644 --- a/lib/capybara/node/finders.rb +++ b/lib/capybara/node/finders.rb @@ -48,7 +48,7 @@ module Finders # @return [Capybara::Node::Element] The found element # @raise [Capybara::ElementNotFound] If the element can't be found before time expires # - def find(*args, **options, &optional_filter_block) + def find(*args, **options, &) options[:session_options] = session_options count_options = options.slice(*Capybara::Queries::BaseQuery::COUNT_KEYS) unless count_options.empty? @@ -57,7 +57,7 @@ def find(*args, **options, &optional_filter_block) "Called from: #{Capybara::Helpers.filter_backtrace(caller)}" ) end - synced_resolve Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block) + synced_resolve Capybara::Queries::SelectorQuery.new(*args, **options, &) end ## @@ -78,9 +78,9 @@ def find(*args, **options, &optional_filter_block) # @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) + def ancestor(*args, **options, &) options[:session_options] = session_options - synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block) + synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &) end ## @@ -101,9 +101,9 @@ def ancestor(*args, **options, &optional_filter_block) # @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) + def sibling(*args, **options, &) options[:session_options] = session_options - synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block) + synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &) end ## @@ -132,8 +132,8 @@ def sibling(*args, **options, &optional_filter_block) # @option options [String, Array, Regexp] class Match fields that match the class(es) passed # @return [Capybara::Node::Element] The found element # - def find_field(locator = nil, **options, &optional_filter_block) - find(:field, locator, **options, &optional_filter_block) + def find_field(locator = nil, **options, &) + find(:field, locator, **options, &) end ## @@ -154,8 +154,8 @@ def find_field(locator = nil, **options, &optional_filter_block) # @option options [String, Array, Regexp] class Match links that match the class(es) provided # @return [Capybara::Node::Element] The found element # - def find_link(locator = nil, **options, &optional_filter_block) - find(:link, locator, **options, &optional_filter_block) + def find_link(locator = nil, **options, &) + find(:link, locator, **options, &) end ## @@ -181,8 +181,8 @@ def find_link(locator = nil, **options, &optional_filter_block) # @option options [String, Array, Regexp] class Match buttons that match the class(es) provided # @return [Capybara::Node::Element] The found element # - def find_button(locator = nil, **options, &optional_filter_block) - find(:button, locator, **options, &optional_filter_block) + def find_button(locator = nil, **options, &) + find(:button, locator, **options, &) end ## @@ -195,8 +195,8 @@ def find_button(locator = nil, **options, &optional_filter_block) # # @return [Capybara::Node::Element] The found element # - def find_by_id(id, **options, &optional_filter_block) - find(:id, id, **options, &optional_filter_block) + def find_by_id(id, **options, &) + find(:id, id, **options, &) end ## @@ -290,9 +290,9 @@ def all(*args, allow_reload: false, **options, &optional_filter_block) # @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) + def first(*args, **options, &) options = { minimum: 1 }.merge(options) unless options_include_minimum?(options) - all(*args, **options, &optional_filter_block).first + all(*args, **options, &).first end private diff --git a/lib/capybara/node/matchers.rb b/lib/capybara/node/matchers.rb index 9d970fddb4..be15d836b0 100644 --- a/lib/capybara/node/matchers.rb +++ b/lib/capybara/node/matchers.rb @@ -267,8 +267,8 @@ def assert_no_selector(*args, &optional_filter_block) # @option options [Integer] :count (nil) Number of times the expression should occur # @return [Boolean] If the expression exists # - def has_xpath?(path, **options, &optional_filter_block) - has_selector?(:xpath, path, **options, &optional_filter_block) + def has_xpath?(path, **options, &) + has_selector?(:xpath, path, **options, &) end ## @@ -279,8 +279,8 @@ def has_xpath?(path, **options, &optional_filter_block) # @param (see #has_xpath?) # @return [Boolean] # - def has_no_xpath?(path, **options, &optional_filter_block) - has_no_selector?(:xpath, path, **options, &optional_filter_block) + def has_no_xpath?(path, **options, &) + has_no_selector?(:xpath, path, **options, &) end ## @@ -306,8 +306,8 @@ def has_no_xpath?(path, **options, &optional_filter_block) # @option options [Integer] :count (nil) Number of times the selector should occur # @return [Boolean] If the selector exists # - def has_css?(path, **options, &optional_filter_block) - has_selector?(:css, path, **options, &optional_filter_block) + def has_css?(path, **options, &) + has_selector?(:css, path, **options, &) end ## @@ -318,8 +318,8 @@ def has_css?(path, **options, &optional_filter_block) # @param (see #has_css?) # @return [Boolean] # - def has_no_css?(path, **options, &optional_filter_block) - has_no_selector?(:css, path, **options, &optional_filter_block) + def has_no_css?(path, **options, &) + has_no_selector?(:css, path, **options, &) end ## @@ -331,8 +331,8 @@ def has_no_css?(path, **options, &optional_filter_block) # @option options [String, Regexp] The attributes values of matching elements # @return [Boolean] Whether it exists # - def has_element?(locator = nil, **options, &optional_filter_block) - has_selector?(:element, locator, **options, &optional_filter_block) + def has_element?(locator = nil, **options, &) + has_selector?(:element, locator, **options, &) end ## @@ -343,8 +343,8 @@ def has_element?(locator = nil, **options, &optional_filter_block) # @param (see #has_element?) # @return [Boolean] Whether it doesn't exist # - def has_no_element?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:element, locator, **options, &optional_filter_block) + def has_no_element?(locator = nil, **options, &) + has_no_selector?(:element, locator, **options, &) end ## @@ -356,8 +356,8 @@ def has_no_element?(locator = nil, **options, &optional_filter_block) # @option options [String, Regexp] :href The value the href attribute must be # @return [Boolean] Whether it exists # - def has_link?(locator = nil, **options, &optional_filter_block) - has_selector?(:link, locator, **options, &optional_filter_block) + def has_link?(locator = nil, **options, &) + has_selector?(:link, locator, **options, &) end ## @@ -368,8 +368,8 @@ def has_link?(locator = nil, **options, &optional_filter_block) # @param (see #has_link?) # @return [Boolean] Whether it doesn't exist # - def has_no_link?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:link, locator, **options, &optional_filter_block) + def has_no_link?(locator = nil, **options, &) + has_no_selector?(:link, locator, **options, &) end ## @@ -380,8 +380,8 @@ def has_no_link?(locator = nil, **options, &optional_filter_block) # @param [String] locator The text, value or id of a button to check for # @return [Boolean] Whether it exists # - def has_button?(locator = nil, **options, &optional_filter_block) - has_selector?(:button, locator, **options, &optional_filter_block) + def has_button?(locator = nil, **options, &) + has_selector?(:button, locator, **options, &) end ## @@ -392,8 +392,8 @@ def has_button?(locator = nil, **options, &optional_filter_block) # @param [String] locator The text, value or id of a button to check for # @return [Boolean] Whether it doesn't exist # - def has_no_button?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:button, locator, **options, &optional_filter_block) + def has_no_button?(locator = nil, **options, &) + has_no_selector?(:button, locator, **options, &) end ## @@ -418,8 +418,8 @@ def has_no_button?(locator = nil, **options, &optional_filter_block) # @option options [String] :type The type attribute of the field # @return [Boolean] Whether it exists # - def has_field?(locator = nil, **options, &optional_filter_block) - has_selector?(:field, locator, **options, &optional_filter_block) + def has_field?(locator = nil, **options, &) + has_selector?(:field, locator, **options, &) end ## @@ -432,8 +432,8 @@ def has_field?(locator = nil, **options, &optional_filter_block) # @option options [String] :type The type attribute of the field # @return [Boolean] Whether it doesn't exist # - def has_no_field?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:field, locator, **options, &optional_filter_block) + def has_no_field?(locator = nil, **options, &) + has_no_selector?(:field, locator, **options, &) end ## @@ -445,8 +445,8 @@ def has_no_field?(locator = nil, **options, &optional_filter_block) # @param [String] locator The label, name or id of a checked field # @return [Boolean] Whether it exists # - def has_checked_field?(locator = nil, **options, &optional_filter_block) - has_selector?(:field, locator, **options.merge(checked: true), &optional_filter_block) + def has_checked_field?(locator = nil, **options, &) + has_selector?(:field, locator, **options.merge(checked: true), &) end ## @@ -458,8 +458,8 @@ def has_checked_field?(locator = nil, **options, &optional_filter_block) # @param [String] locator The label, name or id of a checked field # @return [Boolean] Whether it doesn't exist # - def has_no_checked_field?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:field, locator, **options.merge(checked: true), &optional_filter_block) + def has_no_checked_field?(locator = nil, **options, &) + has_no_selector?(:field, locator, **options.merge(checked: true), &) end ## @@ -471,8 +471,8 @@ def has_no_checked_field?(locator = nil, **options, &optional_filter_block) # @param [String] locator The label, name or id of an unchecked field # @return [Boolean] Whether it exists # - def has_unchecked_field?(locator = nil, **options, &optional_filter_block) - has_selector?(:field, locator, **options.merge(unchecked: true), &optional_filter_block) + def has_unchecked_field?(locator = nil, **options, &) + has_selector?(:field, locator, **options.merge(unchecked: true), &) end ## @@ -484,8 +484,8 @@ def has_unchecked_field?(locator = nil, **options, &optional_filter_block) # @param [String] locator The label, name or id of an unchecked field # @return [Boolean] Whether it doesn't exist # - def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:field, locator, **options.merge(unchecked: true), &optional_filter_block) + def has_no_unchecked_field?(locator = nil, **options, &) + has_no_selector?(:field, locator, **options.merge(unchecked: true), &) end ## @@ -517,8 +517,8 @@ def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block) # @option options [String, Array] :with_selected Partial set of options which should minimally be selected # @return [Boolean] Whether it exists # - def has_select?(locator = nil, **options, &optional_filter_block) - has_selector?(:select, locator, **options, &optional_filter_block) + def has_select?(locator = nil, **options, &) + has_selector?(:select, locator, **options, &) end ## @@ -529,8 +529,8 @@ def has_select?(locator = nil, **options, &optional_filter_block) # @param (see #has_select?) # @return [Boolean] Whether it doesn't exist # - def has_no_select?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:select, locator, **options, &optional_filter_block) + def has_no_select?(locator = nil, **options, &) + has_no_selector?(:select, locator, **options, &) end ## @@ -551,8 +551,8 @@ def has_no_select?(locator = nil, **options, &optional_filter_block) # Partial set of text which should be contained in the tables `` elements organized by column (`` visibility is not considered) # @return [Boolean] Whether it exists # - def has_table?(locator = nil, **options, &optional_filter_block) - has_selector?(:table, locator, **options, &optional_filter_block) + def has_table?(locator = nil, **options, &) + has_selector?(:table, locator, **options, &) end ## @@ -563,8 +563,8 @@ def has_table?(locator = nil, **options, &optional_filter_block) # @param (see #has_table?) # @return [Boolean] Whether it doesn't exist # - def has_no_table?(locator = nil, **options, &optional_filter_block) - has_no_selector?(:table, locator, **options, &optional_filter_block) + def has_no_table?(locator = nil, **options, &) + has_no_selector?(:table, locator, **options, &) end ## @@ -610,8 +610,8 @@ def assert_not_matches_selector(*args, &optional_filter_block) # @param (see #has_selector?) # @return [Boolean] # - def matches_selector?(*args, **options, &optional_filter_block) - make_predicate(options) { assert_matches_selector(*args, options, &optional_filter_block) } + def matches_selector?(*args, **options, &) + make_predicate(options) { assert_matches_selector(*args, options, &) } end ## @@ -621,8 +621,8 @@ def matches_selector?(*args, **options, &optional_filter_block) # @param [String, XPath::Expression] xpath The XPath expression to match against the current code # @return [Boolean] # - def matches_xpath?(xpath, **options, &optional_filter_block) - matches_selector?(:xpath, xpath, **options, &optional_filter_block) + def matches_xpath?(xpath, **options, &) + matches_selector?(:xpath, xpath, **options, &) end ## @@ -632,8 +632,8 @@ def matches_xpath?(xpath, **options, &optional_filter_block) # @param [String] css The CSS selector to match against the current code # @return [Boolean] # - def matches_css?(css, **options, &optional_filter_block) - matches_selector?(:css, css, **options, &optional_filter_block) + def matches_css?(css, **options, &) + matches_selector?(:css, css, **options, &) end ## @@ -644,8 +644,8 @@ def matches_css?(css, **options, &optional_filter_block) # @param (see #has_selector?) # @return [Boolean] # - def not_matches_selector?(*args, **options, &optional_filter_block) - make_predicate(options) { assert_not_matches_selector(*args, options, &optional_filter_block) } + def not_matches_selector?(*args, **options, &) + make_predicate(options) { assert_not_matches_selector(*args, options, &) } end ## @@ -655,8 +655,8 @@ def not_matches_selector?(*args, **options, &optional_filter_block) # @param [String, XPath::Expression] xpath The XPath expression to match against the current code # @return [Boolean] # - def not_matches_xpath?(xpath, **options, &optional_filter_block) - not_matches_selector?(:xpath, xpath, **options, &optional_filter_block) + def not_matches_xpath?(xpath, **options, &) + not_matches_selector?(:xpath, xpath, **options, &) end ## @@ -666,8 +666,8 @@ def not_matches_xpath?(xpath, **options, &optional_filter_block) # @param [String] css The CSS selector to match against the current code # @return [Boolean] # - def not_matches_css?(css, **options, &optional_filter_block) - not_matches_selector?(:css, css, **options, &optional_filter_block) + def not_matches_css?(css, **options, &) + not_matches_selector?(:css, css, **options, &) end ## diff --git a/lib/capybara/queries/selector_query.rb b/lib/capybara/queries/selector_query.rb index 28489df8a8..361ac739cd 100644 --- a/lib/capybara/queries/selector_query.rb +++ b/lib/capybara/queries/selector_query.rb @@ -39,9 +39,9 @@ def initialize(*args, @selector = Selector.new( find_selector(args[0].is_a?(Symbol) ? args.shift : args[0]), config: { - enable_aria_label: enable_aria_label, - enable_aria_role: enable_aria_role, - test_id: test_id + enable_aria_label:, + enable_aria_role:, + test_id: }, format: selector_format ) @@ -600,7 +600,7 @@ def normalize_ws def matches_text_regexp(node, regexp) text_visible = visible text_visible = :all if text_visible == :hidden - node.text(text_visible, normalize_ws: normalize_ws).match(regexp) + node.text(text_visible, normalize_ws:).match(regexp) end def matches_text_regexp?(node, regexp) diff --git a/lib/capybara/queries/text_query.rb b/lib/capybara/queries/text_query.rb index 65376456d1..688bb5dfb6 100644 --- a/lib/capybara/queries/text_query.rb +++ b/lib/capybara/queries/text_query.rb @@ -54,7 +54,7 @@ def exact? def build_message(report_on_invisible) message = +'' - unless (COUNT_KEYS & @options.keys).empty? + if COUNT_KEYS.intersect @options.keys message << " but found #{@count} #{Capybara::Helpers.declension('time', 'times', @count)}" end message << " in #{@actual_text.inspect}" @@ -105,7 +105,7 @@ def check_case_insensitive? def text(node: @node, query_type: @type) normalize_ws = options.fetch(:normalize_ws, session_options.default_normalize_ws) - node.text(query_type, normalize_ws: normalize_ws) + node.text(query_type, normalize_ws:) end def default_type diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index d7b0258798..16a1f1e0c4 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -174,12 +174,12 @@ def rest # while JRuby >= 9.2.8.0 leaks threads when using lazy enumerators # https://github.com/teamcapybara/capybara/issues/2349 # so disable the use and JRuby users will need to pay a performance penalty - def lazy_select_elements(&block) - @elements.select(&block).to_enum # non-lazy evaluation + def lazy_select_elements(&) + @elements.select(&).to_enum # non-lazy evaluation end else - def lazy_select_elements(&block) - @elements.lazy.select(&block) + def lazy_select_elements(&) + @elements.lazy.select(&) end end end diff --git a/lib/capybara/rspec/matcher_proxies.rb b/lib/capybara/rspec/matcher_proxies.rb index e576a357b5..16109ff2ca 100644 --- a/lib/capybara/rspec/matcher_proxies.rb +++ b/lib/capybara/rspec/matcher_proxies.rb @@ -2,11 +2,11 @@ module Capybara module RSpecMatcherProxies - def all(*args, **kwargs, &block) + def all(*args, **kwargs, &) if defined?(::RSpec::Matchers::BuiltIn::All) && args.first.respond_to?(:matches?) ::RSpec::Matchers::BuiltIn::All.new(*args) else - find_all(*args, **kwargs, &block) + find_all(*args, **kwargs, &) end end diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index a7a0f452f6..5eac2bc15d 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -144,8 +144,8 @@ def have_title(title, **options) # RSpec matcher for the current path. # # @see Capybara::SessionMatchers#assert_current_path - def have_current_path(path, **options, &optional_filter_block) - Matchers::HaveCurrentPath.new(path, **options, &optional_filter_block) + def have_current_path(path, **options, &) + Matchers::HaveCurrentPath.new(path, **options, &) end # RSpec matcher for element style. diff --git a/lib/capybara/rspec/matchers/base.rb b/lib/capybara/rspec/matchers/base.rb index dc56205ac4..32cd7f5b3a 100644 --- a/lib/capybara/rspec/matchers/base.rb +++ b/lib/capybara/rspec/matchers/base.rb @@ -88,12 +88,12 @@ def initialize(matcher) @matcher = matcher end - def matches?(actual, &filter_block) - @matcher.does_not_match?(actual, &filter_block) + def matches?(actual, &) + @matcher.does_not_match?(actual, &) end - def does_not_match?(actual, &filter_block) - @matcher.matches?(actual, &filter_block) + def does_not_match?(actual, &) + @matcher.matches?(actual, &) end def description diff --git a/lib/capybara/rspec/matchers/have_selector.rb b/lib/capybara/rspec/matchers/have_selector.rb index 36cca464e5..714ff7c8a9 100644 --- a/lib/capybara/rspec/matchers/have_selector.rb +++ b/lib/capybara/rspec/matchers/have_selector.rb @@ -6,7 +6,7 @@ module Capybara module RSpecMatchers module Matchers class HaveSelector < CountableWrappedElementMatcher - def initialize(*args, **kw_args, &filter_block) + def initialize(*args, **kw_args, &) super return unless (@args.size < 2) && @kw_args.keys.any?(String) diff --git a/lib/capybara/rspec/matchers/match_style.rb b/lib/capybara/rspec/matchers/match_style.rb index 4b60cf9d4d..601d6b05f3 100644 --- a/lib/capybara/rspec/matchers/match_style.rb +++ b/lib/capybara/rspec/matchers/match_style.rb @@ -6,9 +6,9 @@ module Capybara module RSpecMatchers module Matchers class MatchStyle < WrappedElementMatcher - def initialize(styles = nil, **kw_args, &filter_block) + def initialize(styles = nil, **kw_args, &) styles, kw_args = kw_args, {} if styles.nil? - super(styles, **kw_args, &filter_block) + super(styles, **kw_args, &) end def element_matches?(el) @@ -33,7 +33,7 @@ module Matchers ## # @deprecated class HaveStyle < MatchStyle - def initialize(*args, **kw_args, &filter_block) + def initialize(*args, **kw_args, &) warn 'HaveStyle matcher is deprecated, please use the MatchStyle matcher instead' super end diff --git a/lib/capybara/selector/definition.rb b/lib/capybara/selector/definition.rb index 35acf22e39..7238821484 100644 --- a/lib/capybara/selector/definition.rb +++ b/lib/capybara/selector/definition.rb @@ -56,8 +56,8 @@ def expression_filters # @overload xpath() # @return [#call] The block that will be called to generate the XPath expression # - def xpath(*allowed_filters, &block) - expression(:xpath, allowed_filters, &block) + def xpath(*allowed_filters, &) + expression(:xpath, allowed_filters, &) end ## @@ -74,8 +74,8 @@ def xpath(*allowed_filters, &block) # @overload css() # @return [#call] The block that will be called to generate the CSS selector # - def css(*allowed_filters, &block) - expression(:css, allowed_filters, &block) + def css(*allowed_filters, &) + expression(:css, allowed_filters, &) end ## @@ -197,8 +197,8 @@ def describe_all_expression_filters(**opts) end.join end - def describe_node_filters(&block) - describe(:node_filters, &block) + def describe_node_filters(&) + describe(:node_filters, &) end ## diff --git a/lib/capybara/selector/definition/id.rb b/lib/capybara/selector/definition/id.rb index a09e3f1038..c1e144e8a2 100644 --- a/lib/capybara/selector/definition/id.rb +++ b/lib/capybara/selector/definition/id.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true Capybara.add_selector(:id, locator_type: [String, Symbol, Regexp]) do - xpath { |id| builder(XPath.descendant).add_attribute_conditions(id: id) } + xpath { |id| builder(XPath.descendant).add_attribute_conditions(id:) } locator_filter { |node, id| id.is_a?(Regexp) ? id.match?(node[:id]) : true } end diff --git a/lib/capybara/selector/definition/link.rb b/lib/capybara/selector/definition/link.rb index b381171a94..38966d644b 100644 --- a/lib/capybara/selector/definition/link.rb +++ b/lib/capybara/selector/definition/link.rb @@ -3,11 +3,11 @@ Capybara.add_selector(:link, locator_type: [String, Symbol]) do xpath do |locator, href: true, alt: nil, title: nil, target: nil, **| xpath = XPath.descendant(:a) - xpath = builder(xpath).add_attribute_conditions(href: href) unless href == false + xpath = builder(xpath).add_attribute_conditions(href:) unless href == false if enable_aria_role role_path = XPath.descendant[XPath.attr(:role).equals('link')] - role_path = builder(role_path).add_attribute_conditions(href: href) unless [true, false].include? href + role_path = builder(role_path).add_attribute_conditions(href:) unless [true, false].include? href xpath += role_path end @@ -38,7 +38,7 @@ end expression_filter(:download, valid_values: [true, false, String]) do |expr, download| - builder(expr).add_attribute_conditions(download: download) + builder(expr).add_attribute_conditions(download:) end describe_expression_filters do |download: nil, **options| diff --git a/lib/capybara/selector/filter_set.rb b/lib/capybara/selector/filter_set.rb index d65b2548ef..c8a9484e12 100644 --- a/lib/capybara/selector/filter_set.rb +++ b/lib/capybara/selector/filter_set.rb @@ -15,15 +15,15 @@ def initialize(name, &block) instance_eval(&block) if block end - def node_filter(names, *types, **options, &block) + def node_filter(names, *types, **options, &) Array(names).each do |name| - add_filter(name, Filters::NodeFilter, *types, **options, &block) + add_filter(name, Filters::NodeFilter, *types, **options, &) end end alias_method :filter, :node_filter - def expression_filter(name, *types, **options, &block) - add_filter(name, Filters::ExpressionFilter, *types, **options, &block) + def expression_filter(name, *types, **options, &) + add_filter(name, Filters::ExpressionFilter, *types, **options, &) end def describe(what = nil, &block) @@ -75,8 +75,8 @@ def [](name) all.fetch(name.to_sym) { |set_name| raise ArgumentError, "Unknown filter set (:#{set_name})" } end - def add(name, &block) - all[name.to_sym] = FilterSet.new(name.to_sym, &block) + def add(name, &) + all[name.to_sym] = FilterSet.new(name.to_sym, &) end def remove(name) diff --git a/lib/capybara/selector/filters/locator_filter.rb b/lib/capybara/selector/filters/locator_filter.rb index 689284218a..c4268178fc 100644 --- a/lib/capybara/selector/filters/locator_filter.rb +++ b/lib/capybara/selector/filters/locator_filter.rb @@ -11,7 +11,7 @@ def initialize(block, **options) end def matches?(node, value, context = nil, exact:) - apply(node, value, true, context, exact: exact, format: context&.default_format) + apply(node, value, true, context, exact:, format: context&.default_format) rescue Capybara::ElementNotFound false end diff --git a/lib/capybara/selector/regexp_disassembler.rb b/lib/capybara/selector/regexp_disassembler.rb index e86f379d9b..051a42d6c2 100644 --- a/lib/capybara/selector/regexp_disassembler.rb +++ b/lib/capybara/selector/regexp_disassembler.rb @@ -59,7 +59,7 @@ def remove_or_covered(or_series) end def process(alternation:) - strs = extract_strings(Regexp::Parser.parse(@regexp), alternation: alternation) + strs = extract_strings(Regexp::Parser.parse(@regexp), alternation:) strs = collapse(combine(strs).map(&:flatten)) strs.each { |str| str.map!(&:upcase) } if @regexp.casefold? strs diff --git a/lib/capybara/selector/selector.rb b/lib/capybara/selector/selector.rb index 9b6e61fed1..3ad5e49c5e 100644 --- a/lib/capybara/selector/selector.rb +++ b/lib/capybara/selector/selector.rb @@ -11,12 +11,12 @@ def [](name) all.fetch(name.to_sym) { |sel_type| raise ArgumentError, "Unknown selector type (:#{sel_type})" } end - def add(name, **options, &block) - all[name.to_sym] = Definition.new(name.to_sym, **options, &block) + def add(name, **options, &) + all[name.to_sym] = Definition.new(name.to_sym, **options, &) end - def update(name, &block) - self[name].instance_eval(&block) + def update(name, &) + self[name].instance_eval(&) end def remove(name) @@ -79,7 +79,7 @@ def add_error(error_msg) end def expression_for(name, locator, config: @config, format: current_format, **options) - Selector.new(name, config: config, format: format).call(locator, **options) + Selector.new(name, config:, format:).call(locator, **options) end # @api private diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index ad57ddc256..d169fb3eff 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -181,7 +181,7 @@ def frame_obscured_at?(x:, y:) switch_to_frame(:parent) begin - frame.base.obscured?(x: x, y: y) + frame.base.obscured?(x:, y:) ensure switch_to_frame(frame) end diff --git a/lib/capybara/selenium/driver_specializations/chrome_driver.rb b/lib/capybara/selenium/driver_specializations/chrome_driver.rb index cdef839930..2b1d21fd03 100644 --- a/lib/capybara/selenium/driver_specializations/chrome_driver.rb +++ b/lib/capybara/selenium/driver_specializations/chrome_driver.rb @@ -96,7 +96,7 @@ def execute_cdp(cmd, params = {}) if browser.respond_to? :execute_cdp browser.execute_cdp(cmd, **params) else - args = { cmd: cmd, params: params } + args = { cmd:, params: } result = bridge.http.call(:post, "session/#{bridge.session_id}/goog/cdp/execute", args) result['value'] end diff --git a/lib/capybara/selenium/driver_specializations/edge_driver.rb b/lib/capybara/selenium/driver_specializations/edge_driver.rb index d1c67ca3a9..ee72065ed1 100644 --- a/lib/capybara/selenium/driver_specializations/edge_driver.rb +++ b/lib/capybara/selenium/driver_specializations/edge_driver.rb @@ -106,7 +106,7 @@ def execute_cdp(cmd, params = {}) if browser.respond_to? :execute_cdp browser.execute_cdp(cmd, **params) else - args = { cmd: cmd, params: params } + args = { cmd:, params: } result = bridge.http.call(:post, "session/#{bridge.session_id}/ms/cdp/execute", args) result['value'] end diff --git a/lib/capybara/selenium/extensions/find.rb b/lib/capybara/selenium/extensions/find.rb index 51b38e4ac6..6346d79fe6 100644 --- a/lib/capybara/selenium/extensions/find.rb +++ b/lib/capybara/selenium/extensions/find.rb @@ -4,11 +4,11 @@ module Capybara module Selenium module Find def find_xpath(selector, uses_visibility: false, styles: nil, position: false, **_options) - find_by(:xpath, selector, uses_visibility: uses_visibility, texts: [], styles: styles, position: position) + find_by(:xpath, selector, uses_visibility:, texts: [], styles:, position:) end def find_css(selector, uses_visibility: false, texts: [], styles: nil, position: false, **_options) - find_by(:css, selector, uses_visibility: uses_visibility, texts: texts, styles: styles, position: position) + find_by(:css, selector, uses_visibility:, texts:, styles:, position:) end private @@ -19,7 +19,7 @@ def find_by(format, selector, uses_visibility:, texts:, styles:, position:) if (els.size > 2) && !ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS'] els = filter_by_text(els, texts) unless texts.empty? - hints = gather_hints(els, uses_visibility: uses_visibility, styles: styles, position: position) + hints = gather_hints(els, uses_visibility:, styles:, position:) end els.map.with_index { |el, idx| build_node(el, hints[idx] || {}) } end diff --git a/lib/capybara/selenium/extensions/html5_drag.rb b/lib/capybara/selenium/extensions/html5_drag.rb index 9021563ea9..85876960a9 100644 --- a/lib/capybara/selenium/extensions/html5_drag.rb +++ b/lib/capybara/selenium/extensions/html5_drag.rb @@ -40,7 +40,7 @@ def html5_drop(*args) driver.execute_script DROP_FILE, self, input else items = args.flat_map do |arg| - arg.map { |(type, data)| { type: type, data: data } } + arg.map { |(type, data)| { type:, data: } } end driver.execute_script DROP_STRING, items, self end diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index 831e0399df..eccfdff8a9 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -462,7 +462,7 @@ def capabilities end def action_pause(action, duration) - action.pause(device: action.pointer_inputs.first, duration: duration) + action.pause(device: action.pointer_inputs.first, duration:) end def normalize_keys(keys) @@ -476,8 +476,8 @@ def normalize_keys(keys) end end - def each_key(keys, &block) - normalize_keys(keys).each(&block) + def each_key(keys, &) + normalize_keys(keys).each(&) end def find_context diff --git a/lib/capybara/selenium/nodes/firefox_node.rb b/lib/capybara/selenium/nodes/firefox_node.rb index 28843ae011..fdc984e76a 100644 --- a/lib/capybara/selenium/nodes/firefox_node.rb +++ b/lib/capybara/selenium/nodes/firefox_node.rb @@ -127,7 +127,7 @@ def upload(local_file) raise ArgumentError, "You may only upload files: #{local_file.inspect}" unless File.file?(local_file) file = ::Selenium::WebDriver::Zipper.zip_file(local_file) - bridge.http.call(:post, "session/#{bridge.session_id}/file", file: file)['value'] + bridge.http.call(:post, "session/#{bridge.session_id}/file", file:)['value'] end def browser_version diff --git a/lib/capybara/server/checker.rb b/lib/capybara/server/checker.rb index 27f362d038..624a9192be 100644 --- a/lib/capybara/server/checker.rb +++ b/lib/capybara/server/checker.rb @@ -10,10 +10,10 @@ def initialize(host, port) @ssl = false end - def request(&block) - ssl? ? https_request(&block) : http_request(&block) + def request(&) + ssl? ? https_request(&) : http_request(&) rescue *TRY_HTTPS_ERRORS - res = https_request(&block) + res = https_request(&) @ssl = true res end @@ -24,16 +24,16 @@ def ssl? private - def http_request(&block) - make_request(read_timeout: 2, &block) + def http_request(&) + make_request(read_timeout: 2, &) end - def https_request(&block) - make_request(**ssl_options, &block) + def https_request(&) + make_request(**ssl_options, &) end - def make_request(**options, &block) - Net::HTTP.start(@host, @port, options.merge(max_retries: 0), &block) + def make_request(**options, &) + Net::HTTP.start(@host, @port, options.merge(max_retries: 0), &) end def ssl_options diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 1451a91af4..ad51193990 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -376,8 +376,8 @@ def within(*args, **kw_args) # # @param [String] locator Id or legend of the fieldset # - def within_fieldset(locator, &block) - within(:fieldset, locator, &block) + def within_fieldset(locator, &) + within(:fieldset, locator, &) end ## @@ -386,8 +386,8 @@ def within_fieldset(locator, &block) # # @param [String] locator Id or caption of the table # - def within_table(locator, &block) - within(:table, locator, &block) + def within_table(locator, &) + within(:table, locator, &) end ## @@ -656,8 +656,8 @@ def evaluate_async_script(script, *args) # @return [String] the message shown in the modal # @raise [Capybara::ModalNotFound] if modal dialog hasn't been found # - def accept_alert(text = nil, **options, &blk) - accept_modal(:alert, text, options, &blk) + def accept_alert(text = nil, **options, &) + accept_modal(:alert, text, options, &) end ## @@ -666,8 +666,8 @@ def accept_alert(text = nil, **options, &blk) # # @macro modal_params # - def accept_confirm(text = nil, **options, &blk) - accept_modal(:confirm, text, options, &blk) + def accept_confirm(text = nil, **options, &) + accept_modal(:confirm, text, options, &) end ## @@ -676,8 +676,8 @@ def accept_confirm(text = nil, **options, &blk) # # @macro modal_params # - def dismiss_confirm(text = nil, **options, &blk) - dismiss_modal(:confirm, text, options, &blk) + def dismiss_confirm(text = nil, **options, &) + dismiss_modal(:confirm, text, options, &) end ## @@ -687,8 +687,8 @@ def dismiss_confirm(text = nil, **options, &blk) # @macro modal_params # @option options [String] :with Response to provide to the prompt # - def accept_prompt(text = nil, **options, &blk) - accept_modal(:prompt, text, options, &blk) + def accept_prompt(text = nil, **options, &) + accept_modal(:prompt, text, options, &) end ## @@ -697,8 +697,8 @@ def accept_prompt(text = nil, **options, &blk) # # @macro modal_params # - def dismiss_prompt(text = nil, **options, &blk) - dismiss_modal(:prompt, text, options, &blk) + def dismiss_prompt(text = nil, **options, &) + dismiss_modal(:prompt, text, options, &) end ## @@ -797,7 +797,7 @@ def current_scope # # Yield a block using a specific maximum wait time. # - def using_wait_time(seconds, &block) + def using_wait_time(seconds, &) if Capybara.threadsafe begin previous_wait_time = config.default_max_wait_time @@ -807,7 +807,7 @@ def using_wait_time(seconds, &block) config.default_max_wait_time = previous_wait_time end else - Capybara.using_wait_time(seconds, &block) + Capybara.using_wait_time(seconds, &) end end @@ -846,12 +846,12 @@ def driver_args(args) args.map { |arg| arg.is_a?(Capybara::Node::Element) ? arg.base : arg } end - def accept_modal(type, text_or_options, options, &blk) - driver.accept_modal(type, **modal_options(text_or_options, **options), &blk) + def accept_modal(type, text_or_options, options, &) + driver.accept_modal(type, **modal_options(text_or_options, **options), &) end - def dismiss_modal(type, text_or_options, options, &blk) - driver.dismiss_modal(type, **modal_options(text_or_options, **options), &blk) + def dismiss_modal(type, text_or_options, options, &) + driver.dismiss_modal(type, **modal_options(text_or_options, **options), &) end def modal_options(text = nil, **options) @@ -943,9 +943,9 @@ def _switch_to_window_by_locator raise Capybara::WindowError, 'Could not find a window matching block/lambda' end - def synchronize_windows(options, &block) + def synchronize_windows(options, &) wait_time = Capybara::Queries::BaseQuery.wait(options, config.default_max_wait_time) - document.synchronize(wait_time, errors: [Capybara::WindowError], &block) + document.synchronize(wait_time, errors: [Capybara::WindowError], &) end end end diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index b4cc5ffe44..aeeeed254d 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -567,7 +567,7 @@ element.drag_to(target) conditions = %w[DragLeave Drop DragEnd].map do |text| - have_css('div.log', text: text) + have_css('div.log', text:) end expect(@session).to(conditions.reduce { |memo, cond| memo.and(cond) }) diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 785ba306e2..dcbc05dc91 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -73,11 +73,11 @@ def run_specs(session, name, **options, &filter_block) end before :each, :psc do - SpecHelper.reset_threadsafe(bool: true, session: session) + SpecHelper.reset_threadsafe(bool: true, session:) end after psc: true do - SpecHelper.reset_threadsafe(session: session) + SpecHelper.reset_threadsafe(session:) end before :each, :exact_false do diff --git a/spec/sauce_spec_chrome.rb b/spec/sauce_spec_chrome.rb index dc3b3e7856..14b42e73b7 100644 --- a/spec/sauce_spec_chrome.rb +++ b/spec/sauce_spec_chrome.rb @@ -26,8 +26,8 @@ url = 'https://ondemand.saucelabs.com:443/wd/hub' Capybara::Selenium::Driver.new(app, - browser: :remote, url: url, - capabilities: capabilities, + browser: :remote, url:, + capabilities:, options: Selenium::WebDriver::Chrome::Options.new(args: [''])) end diff --git a/spec/selenium_spec_chrome_remote.rb b/spec/selenium_spec_chrome_remote.rb index 8cbdf261f2..3385a76c48 100644 --- a/spec/selenium_spec_chrome_remote.rb +++ b/spec/selenium_spec_chrome_remote.rb @@ -44,7 +44,7 @@ def selenium_gte?(version) Capybara::Selenium::Driver.new app, browser: :remote, options: browser_options, - url: url + url: end CHROME_REMOTE_DRIVER = :selenium_chrome_remote diff --git a/spec/selenium_spec_firefox_remote.rb b/spec/selenium_spec_firefox_remote.rb index 028197945f..4be82d563b 100644 --- a/spec/selenium_spec_firefox_remote.rb +++ b/spec/selenium_spec_firefox_remote.rb @@ -40,7 +40,7 @@ def ensure_selenium_running! Capybara::Selenium::Driver.new app, browser: :remote, options: browser_options, - url: url + url: end FIREFOX_REMOTE_DRIVER = :selenium_firefox_remote diff --git a/spec/selenium_spec_ie.rb b/spec/selenium_spec_ie.rb index 5ec97b8d8e..a053515366 100644 --- a/spec/selenium_spec_ie.rb +++ b/spec/selenium_spec_ie.rb @@ -38,13 +38,13 @@ def server_host url = "http://#{selenium_host}:#{selenium_port}/wd/hub" Capybara::Selenium::Driver.new(app, browser: :remote, - options: options, - url: url) + options:, + url:) else Capybara::Selenium::Driver.new( app, browser: :ie, - options: options + options: ) end end