The problem with this approach is that the previous action that was taken (such as a button click, or some fancy JS /
may not have completed when your expectation runs against
One way to address this is to add an expectation that has waiting logic built into it before the expectation
expect(page).to have_content('Login') expect(current_path).to eq('/login')
An even better way to do this is to use
have_current_path which has
waiting/retry logic built in so you don’t need to remember to always add an extra expectation with waiting above it.