Unit tests hitting development database, not testing

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
culprit.

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

I’m still not sure why it is behaving as described, but I found a
work-around.

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
ActiveRecord::Base.schema_format).

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.