1
학교에서 앱을 제작 중이며이 오류가 발생합니다. 현 시점에서 app walk through는 4.2.6 레일에서 시작되었으며 5.0.0.1을 실행 중입니다.레일즈 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
내 코드입니다. 나는 walk-through에 repo에 비교하고 완벽하게 일치합니다. 나는 무엇을 놓치고 있습니까?
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