3

Rails3.1.0とここからのrecaptchagemを使用しています。ユーザーがサインアップできることを確認するキュウリテストを実行していました。サインアップするには、ユーザーがキャプチャに入力する必要があります。私のテストはキャプチャに触れないことを知っています:

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

しかし、テストはまだ合格です。この手順を使用して、正常なサインアップメッセージがページに表示され、recaptcha失敗メッセージが表示されないことを確認して、成功を確認します。

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

コントローラは、ここで提案されている最初のコントローラとほぼ同じです。

  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が機能しない理由はありますか?開発ではうまくいくようです。

4

2 に答える 2

5

Recaptchaは、デフォルトでは、テスト環境とキュウリ環境でキャプチャを検証しません(検証ロジック構成ロジック、およびデフォルト値を参照)。これがなかった場合、テストは非常に困難になるか、キャプチャはあまり役に立ちません。

于 2012-12-16T17:25:31.083 に答える
4

ベンズの回答に追加して、潜在的な回避策を提供するだけです。

私が行ったRSpecで物事が機能しない(「recaptchaで失敗する」)ことを確認するために

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

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

ありがとうベン

于 2013-12-16T12:20:36.343 に答える