ambethia / recaptcha

ReCaptcha helpers for ruby apps

Home Page:http://github.com/ambethia/recaptcha

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

grecaptcha is not defined in rails 6 on test environment

dangxuanphuc opened this issue · comments

When I run rspec, run to command grecaptcha.execute() in js file then get the error grecaptcha is not defined. Though, I enabled the recaptcha on the test environment Recaptcha.configuration.skip_verify_env.delete("test"). Why?

My issue has several causes and corresponding solution:

  1. event.preventDefault()
    During the submit button click event, I put this command in front of grecaptcha.execute() making the data submission impossible.
  2. By default, reCAPTCHA is skipped in test environtment. To enable it during test, add this command to config/initializers/recaptcha.rb:
    Recaptcha.configuration.skip_verify_env.delete("test")
  3. Finally, verify_recaptcha method always return false when run rspec. Solution:
    allow_any_instance_of(Controller).to receive(:verify_recaptcha?).and_return(true)