私はこの問題を回避するのに非常に困難な時間を抱いています。Cucumber + Capybara + PhantomJS in RailsのjQuery Ajaxのデバッグ
私がしたいのは、私のプロジェクトで簡単なAjaxベースの登録フォームをテストすることです。フォームの提出が成功すると、ウェルカムページにリダイレクトされます。そうでない場合は、問題のある各フィールドに関連する適切な検証エラーが発生します。
奇妙な理由のため、カピバラはリダイレクトに従っていません。 Ajaxコールが行われていて、データベースに登録された新しいアカウントが表示されますが、onSuccess
コールバックがまったく呼び出されていないか、リダイレクトが無視されています。ここで
は、私は(簡潔にするために、私はコードを凝縮しています)で動作するようにしようとしているものです:
特集:
Feature: Registration
In order to obtain a new account
As a prospective customer
I must submit a valid registration form.
@javascript
Scenario: A valid registration attempt
Given an account registration form
When I complete the form with valid values
Then I should be redirected to the welcome screen
テスト:
Given(/^an account registration form$/) do
visit("/signup")
assert current_path == "/signup"
end
When(/^I complete the form with valid values$/) do
within("#signupForm") do
fill_in("email", :with => Faker::Internet.email)
fill_in("name", :with => Faker::Name.name)
fill_in("password", :with => "11111111")
click_link("signupFormSubmit")
end
end
Then(/^I should be redirected to the welcome screen$/) do
assert current_path == "/welcome"
end
JavaScript:
console.log('I am not yet inside you.')
$.post(url, form.serialize(), function(response) {
// everything went well
// let's redirect them to the given page
window.location.replace(response.redirectUrl)
console.log('I am inside you and it is good.')
}, function(response) {
// collect error responses from API
// apply error hints to associated fields
console.log('I am inside you and something went wrong.')
})
大丈夫ですので、この特定のテストは、ユーザーをウェルカム画面にリダイレクトするはずです。 onSuccess
、onFailure
コールバック内で何が起こっているのか分かりませんが、役に立たないものはすべて試しました。コードは実行されていないようです。
私は、テストの実行から次のような出力が得られます。私が例外を発生させる場合、それは拾われない問題ではありません
Then I should be redirected to the welcome screen # features/step_definitions/registration.rb:51
Failed assertion, no message given. (MiniTest::Assertion)
./features/step_definitions/registration.rb:52:in `/^I should be redirected to the welcome screen$/'
features/registration.feature:15:in `Then I should be redirected to the welcome screen'
。また、コールバック内でconsole.log()
への呼び出しも行いません。
誰でもこれを見ましたか?もしそうなら、回避策はありますか?より多くの情報が必要な場合は、私が提供してくれることを喜んでお聞かせください。