How to debug "database does not exist" error in test suite?
capybara, factory-bot, rspec, ruby-on-rails
Solution
After a lot of trial and error, I finally managed to get the test database working. Leaving the following here in case anyone else runs into this issue.
The issue was either an incorrect username in database.yml (While I did change these values, I don't think this was the cause as both development and test were using the same username previously).
Or a small spelling mistake in a config var set up elsewhere `ENV["DATABASE_URL"] = "postgres://localhost/test_db"`. This should have been `test-db`.
Problem
I recently set up a Rails dev environment on a new machine. I'm now trying to run an app's test suite, but keep getting database errors. ``` Failure/Error: user = FactoryGirl.create(:user) PG::ConnectionBad: FATAL: database "test-db" does not exist ``` My database.yml file is set up correctly. I've run `psql -l` and test-db does in fact exist, and this is confirmed by running `rake db:create` where I get an 'already exists' message. I've run `rake db:migrate` and `rake:test:prepare`, but the error still remains. My test set up is as follows ``` group :test do gem 'rspec-rails' gem 'factory_girl_rails' gem 'capybara' gem 'guard-rspec' gem 'spork-rails' gem 'guard-spork' end ``` I'm having no trouble with the development database. Why am I getting a db does not exist error, and what can I do to debug this?