Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 950
Rocky Avatar asked Dec 19 '11 07:12

Rocky


2 Answers

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

like image 189
Thong Kuah Avatar answered Oct 19 '22 06:10

Thong Kuah


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
like image 23
daniel Avatar answered Oct 19 '22 07:10

daniel