为什么重新接收不会导致此测试失败?

时间:2012-12-16 17:14:37

标签: ruby-on-rails cucumber recaptcha

我正在使用Rails 3.1.0和来自here的recaptcha gem。我正在进行黄瓜测试,检查用户是否可以注册。注册需要用户填写验证码。我知道我的测试没有触及验证码:

When /^I create a new account with email: "(.*?)" and password: "(.*?)"$/ do |email, pw|
    click_link "Sign up"
    fill_in "Email", :with => email
    fill_in "Password", :with => pw
    fill_in "Password confirmation", :with => pw
    click_button "Sign up"
end

但测试仍然通过。我通过验证页面上是否存在成功的注册消息来检查成功,并且使用此步骤不存在重新接收失败消息:

Then /^I should (not )?see "(.*)"$/ do |negate, text|
  if negate
    page.should_not have_content text
  else
    page.should have_content text
  end
end

控制器几乎与第一个建议的here相同。

  class RegistrationsController < Devise::RegistrationsController
    def create
      if verify_recaptcha
        super
      else
        build_resource
        clean_up_passwords(resource)
        flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code."      
        flash.delete :recaptcha_error
        render :new
      end
    end
  end

有没有理由说recaptcha在测试环境中不起作用?它似乎在开发中运作良好。

2 个答案:

答案 0 :(得分:5)

默认情况下,Recaptcha不会验证测试和黄瓜环境中的验证码(请参阅verify logicconfiguration logicdefault value)。如果不是这样,那么测试将非常困难,或者验证码不会非常有用。

答案 1 :(得分:3)

只需添加Bens答案并提供潜在的解决方法:

为了确保RSpec中的事情不起作用(“重新开始”,“我已经完成了”)

before do
  Recaptcha.configuration.skip_verify_env.delete("test")
end

after do
  Recaptcha.configuration.skip_verify_env << "test"
end

谢谢Ben

相关问题