Search code examples
ruby-on-rails-3rspeccapybarashoulda

Test to check if any content is there with RSpec


So you can have a test like this:

find(".blah").should have_content("blah blah")

But is there a way to just check if something is in blah?

find(".blah").should have_some_content

Solution

  • I do not believe there is a Capybara::RSpecMatchers for what you want. However, you could use the underlying Capybara::Node::Matchers.

    Try:

    find(".blah").has_no_text?.should be_true
    

    If you really want to use the Capybara::RSpecMatchers, you could use have_content with a regex that looks for any non-whitespace character.

    find(".blah").should have_content(/[^\s]/)