{"record":{"id":"e1b1ec884a3be2b8","repo":"teamcapybara/capybara","slug":"query-negative-failure-message","errorCode":null,"errorMessage":"query.negative_failure_message","messagePattern":"query\\.negative_failure_message","errorType":"exception","errorClass":"Capybara::ExpectationNotMet","httpStatus":null,"severity":"error","filePath":"lib/capybara/node/matchers.rb","lineNumber":721,"sourceCode":"        _verify_text(type_or_text, *args, **opts) do |count, query|\n          unless query.matches_count?(count) && (count.positive? || query.expects_none?)\n            raise Capybara::ExpectationNotMet, query.failure_message\n          end\n        end\n      end\n\n      ##\n      # Asserts that the page or current node doesn't have the given text content,\n      # ignoring any HTML tags.\n      #\n      # @macro text_query_params\n      # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time\n      # @return [true]\n      #\n      def assert_no_text(type_or_text, *args, **opts)\n        _verify_text(type_or_text, *args, **opts) do |count, query|\n          if query.matches_count?(count) && (count.positive? || query.expects_none?)\n            raise Capybara::ExpectationNotMet, query.negative_failure_message\n          end\n        end\n      end\n\n      ##\n      # Checks if the page or current node has the given text content,\n      # ignoring any HTML tags.\n      #\n      # By default it will check if the text occurs at least once,\n      # but a different number can be specified.\n      #\n      #     page.has_text?('lorem ipsum', between: 2..4)\n      #\n      # This will check if the text occurs from 2 to 4 times.\n      #\n      # @macro text_query_params\n      # @return [Boolean]                            Whether it exists\n      #","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/node/matchers.rb#L703-L739","documentation":"assert_no_text raises ExpectationNotMet with query.negative_failure_message ('expected not to find text ...') when the text still occurs (and its count matches the count options) after the wait time. It is the negated TextQuery assertion: any lingering occurrence of the string/regexp is a failure.","triggerScenarios":"page.assert_no_text('Loading') while a spinner with that text is still visible; assert_no_text('Error') after a form submit that re-rendered an error flash; regexp variants matching unexpectedly (/error/i matching 'No errors'); asserting too early while fade-out of the message is still running.","commonSituations":"Spinners/loading text driven by JS that outlives the wait, flash messages persisted across requests in the session, copy appearing in hidden elements (TextQuery sees text content regardless of visibility), negative assertions in shared examples hitting pages that legitimately contain the string.","solutions":["Wait out the removal: assert_no_text('Loading', wait: 10)","Scope the assertion to the region where the text must vanish (within('#main') { assert_no_text('Loading') })","Make the regexp precise so legitimate copy does not match (/\\bError:/ instead of /error/i)","If the text is hidden but present and that is acceptable, assert on a visible selector instead of raw text"],"exampleFix":"# before\npage.assert_no_text('Loading')\n\n# after\npage.assert_no_text('Loading', wait: 10)\n# or scope where it must disappear\nwithin('#content') { page.assert_no_text('Loading', wait: 10) }","handlingStrategy":"validation","validationCode":"return unless page.has_text?('Loading')\npage.assert_no_text('Loading', wait: 10) # only assert while removal is expected","typeGuard":"def text_gone?(page, text, wait: 5)\n  !page.has_text?(text, wait: wait)\nend","tryCatchPattern":"begin\n  page.assert_no_text('Loading', wait: 10)\nrescue Capybara::ExpectationNotMet => e\n  puts e.message # shows where the text still occurs\n  raise\nend","preventionTips":["Scope assert_no_text to the container where the text must disappear","Make regexes precise so legitimate copy does not match","Remember TextQuery sees hidden text too — assert visible selectors if that matters"],"tags":["capybara","assertion","text","negative-assertion","waiting"],"backgroundTag":"unexpected-text-present","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}