Forum: Ruby on Rails Unit tests hitting development database, not testing...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eric N. (Guest)
on 2006-05-28 23:04
I've been working through the AWDWR book (both hard copy first edition
and "beta book" pdf of second and I'm running into some problems when
running unit tests.

Integration tests and functional tests are behaving correctly and are
operating against the test database.  However unit tests try to operate
against the development database and fail.

(ie rake test:unit doesn't appear to respect the environment variable)

Running the unit tests manually (ruby test/unit/test_name.rb ) works.

Running a "rake test" successfully runs the functional, then the
integration, and then reports
"rake aborted!
 Test failures"

Looking at the _development_ log, I see that its trying to drop and
create tables, but and fails due to some dependencies.  This is the
exact same behavoir I see if I run rake test:unit so I think that's the

Looking into the testing.rake file, I see that
unit/functional/integration are all dependent on the db:test:prepare
task.  I can't see why one would use the development environment and the
others use the test?

Eric N. (Guest)
on 2006-05-30 01:58
I'm still not sure why it is behaving as described, but I found a

In the database.rake file, I changed the db:test:prepare task, to always
use db:test:clone_structure (in both sql and ruby modes of

I haven't dug deeper now that I have a work-around, but it still seems
odd that out of the box, the full test suite interacted with the
development database.
This topic is locked and can not be replied to.