0
我想通過與Rspec和Shoulda匹配器的關係來測試has_many。Shoulda匹配器和has_many通過:undefined方法`class_name'爲零: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,但提出的解決方案不幫我。