开发者

rspec and recaptcha

I'm building tests for a user sign-up page. I'm about to add Recaptcha to the page, and I don't know how to 开发者_运维百科account for it in rspec. Specifically, I want my integration test to verify that a user can fill out the page, click on the button, and will be signed up. But with Recaptcha on the page, how do I get Rspec to simulate entering a valid Recaptcha string?


This works for me:

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


Recaptcha by default does not verify the captcha in the test environments.


Use a mock object: http://www.relishapp.com/rspec/rspec-mocks/docs

There's no point trying to test ReCaptcha, so simulate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜