그래서, RSpec을 실행하고 알아 내려고 노력하고있어이 오류 받고 있어요 이유 :나가서 설명하자면 NameError : RSpec에있는 초기화되지 일정
: 여기Failure/Error: 3.times {@post.votes.create(value: 1) }
NameError:
uninitialized constant Vote::PostId
내 사양/모델/post_spec.rb 파일입니다
require 'rails_helper'
describe Post do
describe "vote methods" do
before do
@post = Post.create(title: 'post title', body: 'Post bodies must be pretty long.')
3.times {@post.votes.create(value: 1) }
2.times {@post.votes.create(value: -1) }
end
describe '#up_votes' do
it "counts the number of votes with value = 1" do
expect(@post.up_votes).to eq(3)
end
end
describe '#down_votes' do
it "counts the number of votes with value = -1" do
expect(@post.down_votes).to eq(2)
end
end
describe '#points' do
it "returns the sum of all down and up votes" do
expect(@post.points).to eq(1) # 3 - 2
end
end
end
end
Rspec에 대한 데이터 작성이 실행되기 때문에 왜 그 행을 오류로 표시하는지 이해할 수 없습니다. 그리고 내 파일에서 "Vote :: PostId"를 찾으려고 할 때 찾을 수 없습니다.
'@ post.votes'는'create'가 호출 될 수있는'ActiveRecord :: Relation'의 인스턴스를 반환하므로'@ post.votes.create (value : 1)'은 합법입니다. – Ben