teamcapybara/capybara · error · ArgumentError
The have_none_of_selectors matcher does not support use with
Error message
The have_none_of_selectors matcher does not support use with not_to/should_not
What it means
HaveNoSelectors#does_not_match? raises ArgumentError because negating have_none_of_selectors is ambiguous: 'it is not the case that none are present' collapses to 'some unknown subset exists', which RSpec cannot report meaningfully. The positive form calls assert_none_of_selectors and fails naming any selector that is present.
Source
Thrown at lib/capybara/rspec/matchers/have_selector.rb:52
class HaveAllSelectors < WrappedElementMatcher
def element_matches?(el)
el.assert_all_of_selectors(*@args, **session_query_options, &@filter_block)
end
def does_not_match?(_actual)
raise ArgumentError, 'The have_all_selectors matcher does not support use with not_to/should_not'
end
def description = 'have all selectors'
end
class HaveNoSelectors < WrappedElementMatcher
def element_matches?(el)
el.assert_none_of_selectors(*@args, **session_query_options, &@filter_block)
end
def does_not_match?(_actual)
raise ArgumentError, 'The have_none_of_selectors matcher does not support use with not_to/should_not'
end
def description = 'have no selectors'
end
class HaveAnySelectors < WrappedElementMatcher
def element_matches?(el)
el.assert_any_of_selectors(*@args, **session_query_options, &@filter_block)
end
def does_not_match?(el)
el.assert_none_of_selectors(*@args, **session_query_options, &@filter_block)
end
def description = 'have any selectors'
end
end
endView on GitHub (pinned to 15b5fdb76e)
Solutions
- Use the positive form for 'nothing here': expect(page).to have_none_of_selectors('.a', '.b').
- If you meant 'at least one is present', assert the specific selector positively: expect(page).to have_selector('.a').
- Split the compound expectation into one expectation per selector so each is individually meaningful.
- Remove mechanically-generated not_to wrappers introduced by shared examples or cop autocorrection.
Example fix
# before
expect(page).not_to have_none_of_selectors('.a', '.b')
# after
expect(page).to have_selector('.a').or have_selector('.b') Defensive patterns
Strategy: validation
Prevention
- Use to with have_none_of_selectors for exhaustive absence; use individual have_selector expectations for partial presence.
- Lint for 'not_to have_none_of_selectors' in CI the same way as other negated aggregate matchers.
When it happens
Trigger: expect(page).not_to have_none_of_selectors('.a', '.b'); should_not have_none_of_selectors(:xpath, '//tr') - the negated call path hits does_not_match? and raises.
Common situations: Auto-generated negations from spec templates or shared contexts; refactoring 'should not display these elements' specs by simply adding not_to; one-liners where the author meant 'at least one present' but reached for not_to have_none_of_selectors.
Related errors
- The have_all_selectors matcher does not support use with not
- The match_style matcher does not support use with not_to/sho
- Invalid option #{match.inspect} for :match, should be one of
- Invalid option(s) #{invalid_names}, should be one of #{valid
- #{@type} is not a valid type for a text query
AI-assisted analysis of teamcapybara/capybara@15b5fdb76e (2026-08-21).
Data as JSON: /api/errors/40b263a0055b2a49.
Report an issue: GitHub.