Q:

How to clean up state between scenarios in Capybara/Cucumber?

I have been reading Capybara docs and while it is a great tool for BDD, I could not figure out how to reset state between Scenarios.
I have seen some references to Before/After steps, but they seem to apply between each individual step and not scenarios. I was not able to find any definitive documentation on this topic online.
Note: I am not a ruby developer, dabbling just with Capybara/Cucumber stack, so my exposure to ruby technologies is limited and I might be missing something obvious.

A:

I have seen some references to Before/After steps, but they seem to apply between each individual step and not scenarios
This is not true. Take a look at the documentation:
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.
After hooks will be run after the last step of each scenario, even when there are failing, undefined, pending or skipped steps.
As of cleaning up state, 3rd-party gems like database_cleaner might help. But, again, you can clean the state without relying on any gem, using solely Before and After hooks.

