9
我使用了一些早該的RSpec匹配器來測試我的模型,其中之一是:早該rspec的匹配器:上=>:創建
describe Issue do
it { should_not allow_value("test").for(:priority) }
end
我對這個問題是我在我的模型驗證看起來是這樣的:
validates_format_of :priority, :with => /^(Low|Normal|High|Urgent)$/, :on => :update
那麼運行這個測試時,我得到:
1) 'Issue should not allow priority to be set to "test"' FAILED
Expected errors when priority is set to "test", got errors: category is invalid (nil)title can't be blank (nil)profile_id can't be blank (nil)
驗證不被觸發貝科使用它只能在更新上運行,我如何在更新和創建時使用這些shoulda匹配器?
謝謝@endium。同樣,可以使用'subject {FactoryGirl.create(:user)}'來測試'on::update'-only驗證。 – scarver2 2015-02-23 14:50:33