1
여기에는 여러 개의 유효성 검사가 포함 된 고객 모델이 있으며 유효성 검사 중 하나는 해당 사용자가 존재하는지 확인하기위한 외부 서비스에 액세스합니다.외부 서비스의 유효성 검사를 사용하여 모델을 스터브하는 방법
이describe Customer do
it 'is not valid without a name' do
customer = build_stubbed(:customer, name: nil)
customer.valid?
asserts...
end
it 'is not valid without a full name' do
customer = build_stubbed(:customer, name: 'Test')
customer.valid?
asserts...
end
if 'should check if user really exists' do
customer = build_stubbed(:customer, doc_id: '00000000')
customer.valid?
asserts....
end
other tests...
마지막 항목은 사람이 존재하는지 확인하기 위해 DOC_ID 사용하여 외부 서비스의 유효성을 테스트하지만, 여기에 모든 테스트는 모든 검증은 그래서 난으로 서비스 요청을 stub_request해야 실행 :
그리고 여기에 우리는 모든 검증 테스트 각 테스트 내에서 테스트를하기 전에