{"record":{"id":"983384c3f237b06c","repo":"teamcapybara/capybara","slug":"the-match-style-matcher-does-not-support-use-with","errorCode":null,"errorMessage":"The match_style matcher does not support use with not_to/should_not","messagePattern":"The match_style matcher does not support use with not_to/should_not","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/rspec/matchers/match_style.rb","lineNumber":19,"sourceCode":"# frozen_string_literal: true\n\nrequire 'capybara/rspec/matchers/base'\n\nmodule Capybara\n  module RSpecMatchers\n    module Matchers\n      class MatchStyle < WrappedElementMatcher\n        def initialize(styles = nil, **kw_args, &filter_block)\n          styles, kw_args = kw_args, {} if styles.nil?\n          super(styles, **kw_args, &filter_block)\n        end\n\n        def element_matches?(el)\n          el.assert_matches_style(*@args, **@kw_args)\n        end\n\n        def does_not_match?(_actual)\n          raise ArgumentError, 'The match_style matcher does not support use with not_to/should_not'\n        end\n\n        def description\n          'match style'\n        end\n      end\n    end\n  end\nend\n\nmodule Capybara\n  module RSpecMatchers\n    module Matchers\n      ##\n      # @deprecated\n      class HaveStyle < MatchStyle\n        def initialize(*args, **kw_args, &filter_block)\n          warn 'HaveStyle matcher is deprecated, please use the MatchStyle matcher instead'","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/rspec/matchers/match_style.rb#L1-L37","documentation":"MatchStyle#does_not_match? raises ArgumentError: negating match_style would mean 'the styles are not exactly this set', which mixes many unrelated failures (wrong value, missing property, extra properties) into one opaque assertion. Capybara only supports the positive form, which asserts the element's computed styles match all given key/value pairs exactly.","triggerScenarios":"expect(page).not_to match_style(display: 'none'); expect(find('.modal')).not_to match_style({ 'opacity' => '0' }) - plus the underlying style lookup itself requires a JS-capable driver (see the rack_test NotImplementedError), so this matcher is selenium/cuprite-only territory.","commonSituations":"RSpec style guides pushing negative one-liners; mechanically flipping have_style/match_style assertions during refactors; teams moving from asserting classes to computed styles and keeping the not_to habits.","solutions":["Restate positively with the style set you do expect: expect(find('.modal')).to match_style(display: 'block', opacity: '1').","To assert a single style is absent/different, read it and compare directly: expect(find('.modal').style('display')['display']).to eq('none').","For 'element no longer has style X', assert the state change instead (e.g. hidden class or :visible option), not the negated style set.","Remember style queries need a real browser driver - keep these specs tagged js: true."],"exampleFix":"# before\nexpect(find('.modal')).not_to match_style(display: 'none')\n\n# after\nexpect(find('.modal').style('display')['display']).to eq('block')","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Express style assertions positively with match_style; read single properties via node.style('prop') for targeted comparisons.","Keep style assertions in JS-driver specs (they also fail under rack_test with NotImplementedError)."],"tags":["ruby","capybara","rspec","matchers","styles"],"backgroundTag":"matcher-negation-unsupported","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}