From 0480f90168a40780d1398c75031a255c1819dce8 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sun, 14 Apr 2024 16:08:52 -0700 Subject: [PATCH 1/7] Don't run remote tests for now --- .github/workflows/build.yml | 78 ++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1045d614b..860eb47c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,45 +90,45 @@ jobs: - name: Run tests run: bundle exec rake ${{ matrix.task }} - remote_chrome: - runs-on: ubuntu-latest - - strategy: - matrix: - ruby: ["3.0"] - - steps: - - uses: actions/checkout@v4 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run remote Chrome - run: docker-compose up -d selenium_chrome - - name: Run specs - run: bundle exec rake spec_chrome_remote - - remote_firefox: - runs-on: ubuntu-latest - - strategy: - matrix: - ruby: ["3.1"] - - steps: - - uses: actions/checkout@v4 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run remote Firefox - run: docker-compose up -d selenium_firefox - - name: Run specs - run: bundle exec rake spec_firefox_remote + # remote_chrome: + # runs-on: ubuntu-latest + + # strategy: + # matrix: + # ruby: ["3.0"] + + # steps: + # - uses: actions/checkout@v4 + + # - name: Set up Ruby + # uses: ruby/setup-ruby@v1 + # with: + # ruby-version: ${{ matrix.ruby }} + # bundler-cache: true + # - name: Run remote Chrome + # run: docker-compose up -d selenium_chrome + # - name: Run specs + # run: bundle exec rake spec_chrome_remote + + # remote_firefox: + # runs-on: ubuntu-latest + + # strategy: + # matrix: + # ruby: ["3.1"] + + # steps: + # - uses: actions/checkout@v4 + + # - name: Set up Ruby + # uses: ruby/setup-ruby@v1 + # with: + # ruby-version: ${{ matrix.ruby }} + # bundler-cache: true + # - name: Run remote Firefox + # run: docker-compose up -d selenium_firefox + # - name: Run specs + # run: bundle exec rake spec_firefox_remote non_headless: runs-on: ubuntu-latest From 1c55f64e72653940b30ad66e2b1143e9ce549129 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sat, 13 Apr 2024 12:42:53 -0700 Subject: [PATCH 2/7] Remove support for EOL Ruby 3.0 --- .github/workflows/build.yml | 8 ++-- .rubocop.yml | 2 +- capybara.gemspec | 2 +- lib/capybara.rb | 16 +++---- lib/capybara/driver/base.rb | 4 +- lib/capybara/dsl.rb | 8 ++-- lib/capybara/helpers.rb | 2 +- lib/capybara/node/document.rb | 2 +- lib/capybara/queries/selector_query.rb | 8 ++-- lib/capybara/queries/text_query.rb | 4 +- lib/capybara/result.rb | 8 ++-- lib/capybara/rspec/matcher_proxies.rb | 8 ++-- lib/capybara/selector/definition.rb | 16 +++---- lib/capybara/selector/definition/id.rb | 2 +- lib/capybara/selector/definition/link.rb | 6 +-- lib/capybara/selector/filter_set.rb | 12 ++--- .../selector/filters/locator_filter.rb | 2 +- lib/capybara/selector/regexp_disassembler.rb | 2 +- lib/capybara/selector/selector.rb | 10 ++--- lib/capybara/selenium/driver.rb | 2 +- .../driver_specializations/chrome_driver.rb | 2 +- .../driver_specializations/edge_driver.rb | 2 +- lib/capybara/selenium/extensions/find.rb | 6 +-- .../selenium/extensions/html5_drag.rb | 2 +- lib/capybara/selenium/node.rb | 6 +-- lib/capybara/selenium/nodes/firefox_node.rb | 2 +- lib/capybara/server/checker.rb | 18 ++++---- lib/capybara/session.rb | 44 +++++++++---------- lib/capybara/spec/session/node_spec.rb | 2 +- lib/capybara/spec/spec_helper.rb | 4 +- spec/sauce_spec_chrome.rb | 4 +- spec/selenium_spec_chrome_remote.rb | 2 +- spec/selenium_spec_firefox_remote.rb | 2 +- spec/selenium_spec_ie.rb | 6 +-- 34 files changed, 113 insertions(+), 113 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 860eb47c7..d131108e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["3.0", "3.1", "3.2"] + ruby: ["3.1", "3.2"] task: ["rack_smoke", "cucumber"] steps: @@ -72,7 +72,7 @@ jobs: # Ensure all jobs are run to completion fail-fast: false matrix: - ruby: ["3.0"] + ruby: ["3.1"] task: ["spec_chrome", "spec_firefox"] steps: @@ -95,7 +95,7 @@ jobs: # strategy: # matrix: - # ruby: ["3.0"] + # ruby: ["3.1"] # steps: # - uses: actions/checkout@v4 @@ -137,7 +137,7 @@ jobs: # Ensure all jobs are run to completion fail-fast: false matrix: - ruby: ["3.0"] + ruby: ["3.1"] task: ["spec_chrome", "spec_firefox"] steps: diff --git a/.rubocop.yml b/.rubocop.yml index 58290308f..863f5c5f2 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 d33aac37d..59074c037 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 41c9b5f73..20612169f 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 997463776..17953719f 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 14066d496..d8a633e20 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 90ab6f211..8f887c5be 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 16e151edc..624fc0087 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/queries/selector_query.rb b/lib/capybara/queries/selector_query.rb index 28489df8a..361ac739c 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 65376456d..9d0cea144 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 d7b025879..16a1f1e0c 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 e576a357b..0b5de6d77 100644 --- a/lib/capybara/rspec/matcher_proxies.rb +++ b/lib/capybara/rspec/matcher_proxies.rb @@ -2,17 +2,17 @@ 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 - def within(*args, **kwargs, &block) + def within(*args, **kwargs, &) if block - within_element(*args, **kwargs, &block) + within_element(*args, **kwargs, &) else be_within(*args) end diff --git a/lib/capybara/selector/definition.rb b/lib/capybara/selector/definition.rb index 35acf22e3..a16d83aec 100644 --- a/lib/capybara/selector/definition.rb +++ b/lib/capybara/selector/definition.rb @@ -13,7 +13,7 @@ class Definition extend Forwardable - def initialize(name, locator_type: nil, raw_locator: false, supports_exact: nil, &block) + def initialize(name, locator_type: nil, raw_locator: false, supports_exact: nil, &) @name = name @filter_set = Capybara::Selector::FilterSet.add(name) @match = nil @@ -26,7 +26,7 @@ def initialize(name, locator_type: nil, raw_locator: false, supports_exact: nil, @locator_type = locator_type @raw_locator = raw_locator @supports_exact = supports_exact - instance_eval(&block) + instance_eval(&) end def custom_filters @@ -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 a09e3f103..c1e144e8a 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 b381171a9..38966d644 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 d65b2548e..c8a9484e1 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 689284218..c4268178f 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 e86f379d9..051a42d6c 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 9b6e61fed..3ad5e49c5 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 ab22fa141..ff4bb4cc8 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 cdef83993..2b1d21fd0 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 d1c67ca3a..ee72065ed 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 278889b74..89fd6220b 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 @@ -20,7 +20,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 = begin - gather_hints(els, uses_visibility: uses_visibility, styles: styles, position: position) + gather_hints(els, uses_visibility:, styles:, position:) rescue Selenium::WebDriver::Error::JavascriptError # Unclear how this can happen but issue #2729 indicates it can [] diff --git a/lib/capybara/selenium/extensions/html5_drag.rb b/lib/capybara/selenium/extensions/html5_drag.rb index 9021563ea..85876960a 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 831e0399d..eccfdff8a 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 28843ae01..fdc984e76 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 27f362d03..624a9192b 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 1451a91af..ad5119399 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 56031b6e3..07d73babf 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -584,7 +584,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 785ba306e..dcbc05dc9 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 dc3b3e785..14b42e73b 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 8cbdf261f..3385a76c4 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 7fee34948..63a839507 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 5ec97b8d8..a05351536 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 From f926041790087999dc78146f1d28318aae9996e1 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sun, 14 Apr 2024 12:47:38 -0700 Subject: [PATCH 3/7] more --- .rubocop.yml | 4 +++ lib/capybara/rspec/matchers.rb | 28 ++++++++++---------- lib/capybara/rspec/matchers/base.rb | 8 +++--- lib/capybara/rspec/matchers/have_selector.rb | 2 +- lib/capybara/rspec/matchers/match_style.rb | 6 ++--- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 863f5c5f2..2d1e300fc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -132,6 +132,10 @@ Naming/PredicateName: Exclude: - '**/*/*matchers.rb' +Naming/BlockForwarding: + Exclude: + - 'lib/capybara/node/matchers.rb' + - 'lib/capybara/node/finders.rb' #################### Performance #################### Performance/MethodObjectAsBlock: diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index a7a0f452f..ad7ed2624 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -48,12 +48,12 @@ def match_selector(...) end %i[css xpath].each do |selector| - define_method "have_#{selector}" do |expr, **options, &optional_filter_block| - Matchers::HaveSelector.new(selector, expr, **options, &optional_filter_block) + define_method "have_#{selector}" do |expr, **options, &| + Matchers::HaveSelector.new(selector, expr, **options, &) end - define_method "match_#{selector}" do |expr, **options, &optional_filter_block| - Matchers::MatchSelector.new(selector, expr, **options, &optional_filter_block) + define_method "match_#{selector}" do |expr, **options, &| + Matchers::MatchSelector.new(selector, expr, **options, &) end end @@ -78,8 +78,8 @@ def match_selector(...) # @see Capybara::Node::Matchers#matches_css? %i[link button field select table element].each do |selector| - define_method "have_#{selector}" do |locator = nil, **options, &optional_filter_block| - Matchers::HaveSelector.new(selector, locator, **options, &optional_filter_block) + define_method "have_#{selector}" do |locator = nil, **options, &| + Matchers::HaveSelector.new(selector, locator, **options, &) end end @@ -114,8 +114,8 @@ def match_selector(...) # @see Capybara::Node::Matchers#has_table? %i[checked unchecked].each do |state| - define_method "have_#{state}_field" do |locator = nil, **options, &optional_filter_block| - Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &optional_filter_block) + define_method "have_#{state}_field" do |locator = nil, **options, &| + Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &) end end @@ -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. @@ -167,15 +167,15 @@ def have_style(styles = nil, **options) %w[selector css xpath text title current_path link button field checked_field unchecked_field select table sibling ancestor element].each do |matcher_type| - define_method "have_no_#{matcher_type}" do |*args, **kw_args, &optional_filter_block| - Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &optional_filter_block)) + define_method "have_no_#{matcher_type}" do |*args, **kw_args, &| + Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &)) end end alias_method :have_no_content, :have_no_text %w[selector css xpath].each do |matcher_type| - define_method "not_match_#{matcher_type}" do |*args, **kw_args, &optional_filter_block| - Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &optional_filter_block)) + define_method "not_match_#{matcher_type}" do |*args, **kw_args, &| + Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &)) end end diff --git a/lib/capybara/rspec/matchers/base.rb b/lib/capybara/rspec/matchers/base.rb index dc56205ac..32cd7f5b3 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 36cca464e..714ff7c8a 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 4b60cf9d4..601d6b05f 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 From 65b7625c6f795adf7e64b78b507cd06b4dee2c9e Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sun, 14 Apr 2024 12:55:41 -0700 Subject: [PATCH 4/7] Test on ruby 3.3 too --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d131108e1..96a891892 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["3.1", "3.2"] + ruby: ["3.1", "3.2", "3.3"] task: ["rack_smoke", "cucumber"] steps: From a352dc84d2dc37acf32dc7a433e8748398fbabfb Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sun, 14 Apr 2024 15:28:54 -0700 Subject: [PATCH 5/7] define_method doesn't support anonymous blocks --- lib/capybara/rspec/matchers.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index ad7ed2624..604f2568d 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -48,12 +48,12 @@ def match_selector(...) end %i[css xpath].each do |selector| - define_method "have_#{selector}" do |expr, **options, &| - Matchers::HaveSelector.new(selector, expr, **options, &) + define_method "have_#{selector}" do |expr, **options, &filter_block| + Matchers::HaveSelector.new(selector, expr, **options, &filter_block) end - define_method "match_#{selector}" do |expr, **options, &| - Matchers::MatchSelector.new(selector, expr, **options, &) + define_method "match_#{selector}" do |expr, **options, &filter_block| + Matchers::MatchSelector.new(selector, expr, **options, &filter_block) end end @@ -78,8 +78,8 @@ def match_selector(...) # @see Capybara::Node::Matchers#matches_css? %i[link button field select table element].each do |selector| - define_method "have_#{selector}" do |locator = nil, **options, &| - Matchers::HaveSelector.new(selector, locator, **options, &) + define_method "have_#{selector}" do |locator = nil, **options, &filter_block| + Matchers::HaveSelector.new(selector, locator, **options, &filter_block) end end @@ -114,8 +114,8 @@ def match_selector(...) # @see Capybara::Node::Matchers#has_table? %i[checked unchecked].each do |state| - define_method "have_#{state}_field" do |locator = nil, **options, &| - Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &) + define_method "have_#{state}_field" do |locator = nil, **options, &filter_block| + Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &filter_block) end end @@ -167,15 +167,15 @@ def have_style(styles = nil, **options) %w[selector css xpath text title current_path link button field checked_field unchecked_field select table sibling ancestor element].each do |matcher_type| - define_method "have_no_#{matcher_type}" do |*args, **kw_args, &| - Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &)) + define_method "have_no_#{matcher_type}" do |*args, **kw_args, &filter_block| + Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &filter_block)) end end alias_method :have_no_content, :have_no_text %w[selector css xpath].each do |matcher_type| - define_method "not_match_#{matcher_type}" do |*args, **kw_args, &| - Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &)) + define_method "not_match_#{matcher_type}" do |*args, **kw_args, &filter_block| + Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &filter_block)) end end From cc01c56b4c9c662250e49ebdc78dae3e16baac45 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sun, 14 Apr 2024 15:35:40 -0700 Subject: [PATCH 6/7] Fix syntax error --- lib/capybara/selector/filter_set.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/capybara/selector/filter_set.rb b/lib/capybara/selector/filter_set.rb index c8a9484e1..0360c2f83 100644 --- a/lib/capybara/selector/filter_set.rb +++ b/lib/capybara/selector/filter_set.rb @@ -15,9 +15,9 @@ def initialize(name, &block) instance_eval(&block) if block end - def node_filter(names, *types, **options, &) + def node_filter(names, *types, **options, &filter_block) Array(names).each do |name| - add_filter(name, Filters::NodeFilter, *types, **options, &) + add_filter(name, Filters::NodeFilter, *types, **options, &filter_block) end end alias_method :filter, :node_filter From bf0d66780ec02247efc6609e1012d983d384d508 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sun, 14 Apr 2024 15:48:35 -0700 Subject: [PATCH 7/7] missing parameter name --- lib/capybara/rspec/matcher_proxies.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/capybara/rspec/matcher_proxies.rb b/lib/capybara/rspec/matcher_proxies.rb index 0b5de6d77..16109ff2c 100644 --- a/lib/capybara/rspec/matcher_proxies.rb +++ b/lib/capybara/rspec/matcher_proxies.rb @@ -10,9 +10,9 @@ def all(*args, **kwargs, &) end end - def within(*args, **kwargs, &) + def within(*args, **kwargs, &block) if block - within_element(*args, **kwargs, &) + within_element(*args, **kwargs, &block) else be_within(*args) end