Shoulda Matcher和has_many通过:未定义的方法`class_name’为nil:NilClass

我试图通过与Rspec和Shoulda匹配器的关系测试a:has_many。

# 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 

我发现了这个问题 ,但提出的解决方案对我没有帮助。

结果certificate这是一个拐点问题。 我的模型并没有像我的例子那样被称为另一种语言。

我不得不为我的一个模型指定一个变形器,所以我的协会会起作用。

rspec或者最后没有问题。