2016-08-21 1 views
0

Rspec 및 Shoulda와의 관계를 통해 has_many를 테스트하려고합니다.Shoulda Matcher와 has_many through : nil 클래스에 대한 정의되지 않은 메소드 class_name

# student.rb 
has_many :presences 
has_many :calls, through: :presences 

# student_spec.rb 
it { should have_many(:presences) } 
it { should have_many(:calls).through(:presences) } 

#presence.rb 
belongs_to :call 
belongs_to :student 

#presence_spec.rb 
it { should belong_to(:call) } 
it { should belong_to(:student) } 

#call.rb 
has_many :presences 
has_many :students, through: :presences 

#call_spec.rb 
it { should have_many(:presences) } 
it { should have_many(:students).through(:presences) } 

만이 시험의 마지막 반환, 실패

NoMethodError: 
undefined method `class_name' for nil:NilClass 
Did you mean? class_eval 

내가 this issue을 찾았지만, 제안 된 솔루션은 나에게 도움이되지 않습니다.

답변

0

변덕 문제입니다. 내 모델이 다른 언어로되어 있기 때문에 제 모델이 정확히 부르지 않았습니다.

내 모델의 복수형에 대한 굴곡 장치를 지정해야하므로 내 연관성이 작동합니다.

마지막으로 rspec 또는 shoulda에서 문제가 없습니다.

관련 문제