Rocky
Rocky

Reputation: 5716

why 'rake test' is trying to connect to my development DB?

I have my config/database.yml like this:

development:
  adapter: postgresql
  database: psql_dev
  username: postgres
  min_messages: WARNING

test:
  adapter: sqlite3
  database: db/test.sqlite3
  min_messages: WARNING

When I run rake test:units, it reports an error:

rake aborted!

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Why didn't it connect to my test DB(db/test.sqlite3).

and, If I run the test like this rake test RAILS_ENV=test, it works well.

Isn't RAILS_ENV=test the default setting for rake test?

I'm running rails 2.3.5 with ruby 1.8.7, and my $RAILS_ENV is not defined in my shell.

Upvotes: 6

Views: 1351

Answers (2)

Thong Kuah
Thong Kuah

Reputation: 3283

What's happening is that rake test depends on rake db:test:prepare which will attempt to load the current schema from the development database. That's how the test database gets updated when a migration is run on the development database

Upvotes: 3

daniel
daniel

Reputation: 9845

do you have a test:units rake task? Run:

rake test

does that work? Also can you paste the output of:

rake -T | grep tests

Upvotes: 1

Related Questions