2016-08-21 14 views
0

私は:has_many through RspecとShouldaマッチャーとの関係をテストしようとしています。Shoulda Matcherとhas_many through:未定義メソッド `class_name 'for nil:NilClass

# 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からの問題はありません。

関連する問題