{"record":{"id":"d627a65a8c5dc35d","repo":"teamcapybara/capybara","slug":"match-queries-don-t-support-quantity-options-inva","errorCode":null,"errorMessage":"Match queries don't support quantity options. Invalid keys - #{invalid_options.join(', ')}","messagePattern":"Match queries don't support quantity options\\. Invalid keys - #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/queries/match_query.rb","lineNumber":15,"sourceCode":"# frozen_string_literal: true\n\nmodule Capybara\n  module Queries\n    class MatchQuery < Capybara::Queries::SelectorQuery\n      def visible\n        options.key?(:visible) ? super : :all\n      end\n\n    private\n\n      def assert_valid_keys\n        invalid_options = @options.keys & COUNT_KEYS\n        unless invalid_options.empty?\n          raise ArgumentError, \"Match queries don't support quantity options. Invalid keys - #{invalid_options.join(', ')}\"\n        end\n\n        super\n      end\n\n      def valid_keys\n        super - COUNT_KEYS\n      end\n    end\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/queries/match_query.rb#L1-L27","documentation":"MatchQuery (the query behind assert_matches_selector / matches_selector?) rejects any of COUNT_KEYS (count, minimum, maximum, between) with ArgumentError before running. Matching is about whether one specific element satisfies a selector; quantity options are meaningless there because the candidate set is the single node. The check intersects @options.keys with COUNT_KEYS and reports exactly which keys were illegal, then (if none) falls back to the normal valid-keys check.","triggerScenarios":"el.assert_matches_selector('li', count: 2); el.matches_selector?('a', minimum: 1); has_selector?-style copy-paste carrying :count into a match assertion: el.assert_matches_selector('button', between: 1..2); also style/text queries don't accept counts, but this specific message is MatchQuery's.","commonSituations":"Refactoring an assert_selector('li', count: 2) into an element-level matches assertion without dropping the count option, helper methods forwarding a shared options hash into match queries, test templates that always add minimum: 1.","solutions":["Remove the quantity option: el.assert_matches_selector('li')","If you need to assert quantity, do it at the collection level: element.assert_selector('li', count: 2) or expect(el).to have_selector('li', count: 2)","Strip count keys when forwarding shared option hashes into match APIs: opts.except(*%i[count minimum maximum between])"],"exampleFix":"# before\nel.assert_matches_selector('li', count: 2)\n\n# after\nel.assert_matches_selector('li')\nel.assert_selector('li', count: 2)  # quantity belongs here","handlingStrategy":"validation","validationCode":"count_keys = %i[count minimum maximum between]\nel.assert_matches_selector('li') if (opts.keys & count_keys).empty?","typeGuard":"def match_query_opts?(opts)\n  (opts.keys & %i[count minimum maximum between]).empty?\nend","tryCatchPattern":"begin\n  el.assert_matches_selector('li', **opts)\nrescue ArgumentError => e\n  raise unless e.message.include?('quantity options')\n  el.assert_matches_selector('li', **opts.except(*%i[count minimum maximum between]))\nend","preventionTips":["Never copy count options from assert_selector into match assertions","Assert quantities with assert_selector/have_selector on the container","Sanitize shared option hashes with except(*Capybara::Queries::BaseQuery::COUNT_KEYS) before match APIs"],"tags":["capybara","argumenterror","match-query","count-options","validation"],"backgroundTag":"count-option-not-supported","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}