Closed flypiggy closed 8 years ago
这种情况下测试是无法通过的
def send_verify_code
user = current_user || User.new(user_create_params)
if verify_rucaptcha?(user) && user.valid?
send_register_code
else
render json: { errors: user.errors.full_messages }, status: :not_acceptable
end
end
context 'verify captcha failed' do
it 'should return error' do
get 'send_verify_code', user: { email: 'test@geekpark.net' }
expect(response).to have_http_status(:not_acceptable)
expect(JSON.parse(response.body)['errors']).to include('Captcha invalid!')
end
end
updated
校验验证码过期时间失败后, 方法会直接 return. 后面的向 resource 中添加 error 的代码不会执行到.