Why does adding “sleep 1” in an after hook cause this Rspec/Capybara test to pass?

I suspect that it’s possible in your application for the comment to disappear from the page (which is the last thing you’re asserting) before it’s deleted from the database. That means that the test can clean up before the deletion happens. If this is the case you can fix it by waiting for the actual … Read more