In your helper change
config.after(:each) do
DatabaseCleaner.clean
endto
config.append_after(:each) do
DatabaseCleaner.clean
endafter is in fact an alias for prepend_after, which means DatabaseCleaner.clean will run before Capybara and its drivers terminate all connections.
Stopping Capybara first and then cleaning the database will ensure no errors will arise from requests that Capybara's driver makes because of already cleaned database. The requests that are yielding errors don't even necessarily have to be explicitly issued by you - it's enough that one of tons of requests that a browser makes fails.