私はテストに非常に慣れていないので、ここで何をデバッグすべきかよくわかりません。
とはいえ、Users にサブクラス化された Authors と Readers という 2 つの異なるユーザー タイプがあります。
どちらも私のアプリで問題なくサインアップでき、Readers のテストは問題なく動作します。
Authors のサインアップ フォームには、Stripe 支払いフォームが含まれており、フォームを送信する前に、Stripe の API へのリモート呼び出しを行います。
テストは次のようになります。
require 'spec_helper'
feature 'Author sign up' do
scenario 'author can see signup form' do
visit root_path
expect(page).to have_css 'form#new_author'
end
scenario 'user signs up and is logged in' do
visit root_path
fill_in 'author[email]', :with => 'author@example.com'
fill_in 'author[password]', :with => '123456'
fill_in 'author[password_confirmation]', :with => '123456'
fill_in 'author[name]', :with => 'joe shmoe'
fill_in 'author[zipcode]', :with => '02021'
fill_in 'card_number', :with => '4242424242424242'
fill_in 'card_code', :with => '123'
select "1 - January", :from => 'card_month'
select "2014", :from => 'card_year'
find('.author_signup_button').click
expect(page).to have_css '.author_menu'
end
end
このテストとリーダー テストの唯一の違いは、クレジット カードのフォームです。
このアカウントの作成を処理するコントローラーは次のようになります。
def create
@author = Author.new(params[:author])
if @author.save_with_payment
sign_in @author, :event => :authentication
redirect_to root_path, :notice => "Thanks for signing up!"
else
render :nothing => true
end
end
ここにelseがない場合、テストはすぐに失敗し、テンプレートが見つからないことが示されます。つまり、「save_with_payment」メソッドを渡さないことを意味します。これは、フォームがストライプにヒットしないという考えをサポートしています。
エラーは単に言う:
**Failure/Error: expect(page).to have_css '.author_menu'
expected css ".author_menu' to return something**
これは、ストライプと統合する前に機能していたので、ajax 呼び出しに関係していると確信しています。
ajax をサポートするためにすべきことはありますか?