Here we have a Customer model with multiple validations, and one of the validation access an external service to validate if the person exists.
And here we test all validations:
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...
The last item test the external service validation using doc_id to check if the person exists, but here every test runs all validations so should i stub_request the service request with before or stub it within each test?