9
만들 :했어야 RSpec에는 정합 :에 => : 나는 시험에 내 모델, 그들 중 하나가되고를 진작 RSpec에 매처 (matcher)의 일부를 사용하고
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)
BECA 업데이트를 실행할 때만 사용하십시오. 업데이트와 작성시 이러한 shoulda matchers를 어떻게 사용할 수 있습니까?
감사합니다. @endium. 비슷하게,'subject {FactoryGirl.create (: user)}'는'on : : update' 만 검증을 테스트하는데 사용될 수 있습니다. – scarver2