1
私は学校でアプリケーションをビルドしていますが、このエラーが発生しています。現時点では、アプリのウォークスルーは4.2.6で始まり、5.0.0.1を実行しています。Rails 5でレコード作成でテストが失敗する
エラーは次のとおりです。次のように
Failures:
1) Post Creation can be created
Failure/Error: expect(@post).to be_valid
expected #<Post id: nil, date: "2016-12-20", rationale: "Anything", created_at: nil, updated_at: nil, user_id: nil> to be valid, but got errors: User must exist
# ./spec/models/post_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.65569 seconds (files took 2.19 seconds to load)
10 examples, 1 failure
Failed examples:
rspec ./spec/models/post_spec.rb:9 # Post Creation can be created
私のコードです。私はウォークスルーのレポと比べると完璧にマッチします。私は何が欠けていますか?
require 'rails_helper'
RSpec.describe Post, type: :model do
describe "Creation" do
before do
@post = Post.create(date: Date.today, rationale: "Anything")
end
it "can be created" do
expect(@post).to be_valid
end
it "cannot be created without a date and rationale" do
@post.date = nil
@post.rationale = nil
expect(@post).to_not be_valid
end
end
end
'test.log'ファイルを確認してください。何らかの理由でレコードがデータベースに保存されていなかったため、ログを調べずに正確に理由を言うのは不可能です。 – mudasobwa