Today I Learned

Giant Monkeys Learning

Capybara content matchers cheat sheet

There’s a cheat sheet I use to determine the capybara content matcher to use for a specific purpose:

Wait for some text to eventually be there:
expect(page).to have_content('some text')

Succeeds as soon as the text is there and can be very fast.

Wait for some text to be - and stay - there:
expect(page).not_to have_no_content('some text')

Succeeds if the text stays there for the whole default_max_wait_time and is therefore always slow. But sometimes needed.

Wait for some text to eventually disappear:
expect(page).to have_no_content('some text')

Succeeds as soon as this text is not there and can be very fast.

Wait for some text to be - and stay - absent:
expect(page).not_to have_content('some text')

Succeeds if the text stays absent for the whole default_max_wait_time and is therefore always slow. But sometimes needed.