rspec和recaptcha

Kev*_*vin 4 rspec ruby-on-rails recaptcha

我正在为用户注册页面构建测试.我准备将Recaptcha添加到页面中,我不知道如何在rspec中对其进行说明.具体来说,我希望我的集成测试验证用户是否可以填写页面,单击按钮,然后注册.但是在页面上使用Recaptcha,我如何让Rspec模拟输入有效的Recaptcha字符串?

sau*_*uda 9

这对我有用:

context 'User login with captcha' do
  it 'should login with correct recaptcha' do
    LoginController.any_instance.expects(:verify_recaptcha).returns(true)
    user = with_user # get your user...
    post :login, { :username => user.username, :password => user.password }
    session[:user].should eql(user.id)
    response.should redirect_to(root_path)
  end
end
Run Code Online (Sandbox Code Playgroud)


ilg*_*gam 7

默认情况下,Recaptcha不会验证测试环境中的验证码.