David Ham David Ham - 3 months ago 15
Ruby Question

Spring rspec can't connect to the database

I have a new Rails 5 app. I installed the

spring
and
spring-commands-rspec
gems as specified in their directions. I can run
rspec
by itself and the tests run fine. However, if I run the Spring binstub
bin/rspec
I get this:

Running via Spring preloader in process 227
/usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `new'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `connect'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `new'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
etc...


I have a Rails 4 app that uses the binstubs and
bin/rspec
works great. What gives?

Incidentally,
rake spec
fails the same way, with that database connection error.

Answer

Embarrassing. I had not set up my database.yml properly to inherit settings from *default, so the message above literally was telling me there was no database running. Once I got that fixed, the binstub worked again.

Comments