当我运行我的rspec测试时,我收到验证错误year is required
,但在我的工厂中我设置了年份值。我不知道为什么会收到这个错误。
FactoryBot.define do
factory :syllabus do
year { 2019 }
cycle_academic { "1" }
modality { "presencial" }
syllabus_content { "{}" }
association :doc_template
association :user
association :curriculum_course
association :cycle
credits { 4 }
weekly_hours { 5 }
trait :syllabus_estrategia do
course { :estrategia }
end
trait :syllabus_ingles1 do
course { :ingles1 }
end
trait :syllabus_ingles2 do
course { :ingles2 }
end
trait :syllabus_matematica do
course { :matematica }
end
end
end
在我的rspec文件中,我使用此行调用此工厂
it "order to approver" do
syllabus_general = FactoryBot.create(:syllabus)
end
您所显示的工厂中的year
值没有任何问题,因此我猜测您在此工厂中拥有的相关模型之一也需要year
,而其他型号的默认工厂不提供它。
随着工厂总是在思考其他事情正在发生。