I've been seeing this issue consistently for a while now. Basically, when I start spork, if I run "rake" first, I always get this error message:
FOO::Error: ERROR: database "foo_test" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.
: DROP DATABASE IF EXISTS "foo_test"
If I run any unit test via rspec directly, it will work, and then rake will work every time until I restart the server.
We're also using database-cleaner, if that matters.
this affects me as well...
+1 here too
This is because rake does a db:test:prepare, which tries to drop the test database, but spork holds on to a connection to the test database after the prefork block completes. I fixed this by adding this line to the bottom of my prefork block:
p "Done setting up. Closing DB connections in test"
I did not have to add any connection code to the each_run block - apparently Rails will re-establish whatever connections it needs.
Sent a pull request to spork-rails that will fix it: sporkrb/spork-rails#9
Just removing the connection did not do the trick for me, Rails 3.2.6 did not re-establish it.
And it works perfectly now.