【发布时间】:2019-01-09 16:26:53
【问题描述】:
我有模特
class Certificate < ApplicationRecord
notification_object
belongs_to :user
belongs_to :share_class, optional: true
belongs_to :round, optional: true
belongs_to :company, optional: true
has_many :approvals, as: :votable
end
此模型的规格如下所示
需要'rails_helper'
RSpec.describe Certificate, type: :model do
it { should belong_to(:user) }
it { should belong_to(:share_class).optional }
it { should belong_to(:round).optional }
it { should belong_to(:company).optional }
it { should have_many(:approvals) }
end
但是当我运行这个规范时,我得到了这个错误
1) 证书应该属于 share_class 可选:true
Failure/Error: it { should belong_to(:share_class).optional }
Expected Certificate to have a belongs_to association called share_class (the association should have been defined with`optional: true`, but was not)
# ./spec/models/certificate_spec.rb:5:in `block (2 levels) in <top (required)>'
我不知道为什么会出现这个错误。
【问题讨论】:
-
其他可选规格是否通过?
-
@Anthony 是的,这就是为什么它让我感到困惑
标签: ruby-on-rails ruby rspec rspec-rails shoulda