ruby-on-railstestingtestunitruby-on-rails-6

How to test the opposite of assert_text in Ruby on Rails


I want to be sure my page does not contain certain text, I know there is an assert_text function, but, how do I test the opposite?

I am using RoR 6.0, the default test framework (I think it is Test Unit) and capybara


Solution

  • Rails 6 is using Minitest and Capybara by default.

    assert_text comes from Capybara, or to be more precise, from Capybara::Minitest::Assertions.

    As you can see in Capybara::Minitest::Assertions, there is an assertion called assert_no_text, which, I suppose, does exactly what you need.

    Further details can be found here.

    And this is a link to a quick explanation of the difference between Test::Unit and Minitest.

    Hope this helps.