Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 492
Kevin Avatar asked Dec 02 '22 03:12

Kevin


2 Answers

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
like image 150
sauloarruda Avatar answered Dec 30 '22 08:12

sauloarruda


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

like image 30
ilgam Avatar answered Dec 30 '22 06:12

ilgam