I am doing the RoR requests test and I am getting this error:
An error occurred while loading ./spec/requests/posts_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
ActiveRecord::ConnectionNotEstablished:
connection to server at "localhost" (::1), port 5432 failed: fe_sendauth: no password supplied
# ./spec/rails_helper.rb:28:in `<top (required)>'
# ./spec/requests/posts_spec.rb:1:in `<top (required)>'
# ------------------
# --- Caused by: ---
# PG::ConnectionBad:
# connection to server at "localhost" (::1), port 5432 failed: fe_sendauth: no password supplied
# ./spec/rails_helper.rb:28:in `<top (required)>'
And this is my test code for it:
require 'rails_helper'
RSpec.describe 'Users', type: :request do
describe 'GET #index' do
before(:example) { get "/users" }
it 'is a success' do
expect(response).to have_http_status(:ok)
end
it "renders 'index' template" do
expect(response).to render_template(:index)
end
it "shows the rendered text 'Welcome to the Ruby on Rails Blog'" do
expect(response).to include('Welcome to the Ruby on Rails Blog')
end
end
end
I provided my username and password in database.yml and I don't know why get this error. My config for database.yml
development:
<<: *default
database: blog_app
host: 127.0.0.1
username: {username}
password: {password}
CodePudding user response:
You specified the development database. Tests run under a different one.
Add the following to your database.yml
.
test:
<<: *default
database: test_blog_app
host: 127.0.0.1
username: {username}
password: {password}