我正在做 RoR 請求測驗,我收到了這個錯誤:
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)>'
這是我的測驗代碼:
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
我在 database.yml 中提供了我的用戶名和密碼,但我不知道為什么會出現此錯誤。我對 database.yml 的配置
development:
<<: *default
database: blog_app
host: 127.0.0.1
username: {username}
password: {password}
uj5u.com熱心網友回復:
您指定了開發資料庫。測驗在不同的環境下運行。
將以下內容添加到您的database.yml.
test:
<<: *default
database: test_blog_app
host: 127.0.0.1
username: {username}
password: {password}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471101.html
標籤:轨道上的红宝石 红宝石 PostgreSQL rspec-rails
上一篇:使用ActiveRecord進行類似重復查詢的最佳實踐
下一篇:在編輯頁面上未選擇屬性
