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