我努力學習rspec的和已經遇到了一個問題,我想測試我的車型之一的唯一性驗證,但測試不停地進行故障即使我敢肯定它應該通過。測試驗證的唯一
這裏是我的測試:
context "two products with the same title" do
Given{FactoryGirl.build(:product, title: "Hello test title")}
Given(:post2){FactoryGirl.build(:product, title: "Hello test title")}
Then{post2.invalid?}
end
,這裏是我的驗證:
validates :title, uniqueness: true
但是當我運行測試它回來失敗,我不知道爲什麼?
任何幫助將是巨大的!
哪裏是唯一的驗證?您只是驗證標題的最小長度。 –