1

BraintreeのTransparentRedirectAPIにPOSTするRailsアプリの統合テストがあります。基本的に、テストは有効なデータをフォームに入力し、正しい応答が返されることを期待します。私はBraintreeの検証のすべてをテストしようとしているのではなく、ほとんどの場合、フォームが機能することを確認するために1つのテストが必要です。

しかし、私のフォームはこのエラーをスローしています:

1) Braintree CreditCard integration creates a credit card on Braintree and locally
Failure/Error: click_on 'Add card'
ActionController::RoutingError:
   No route matches [POST] "/merchants/XXX/transparent_redirect_requests"

問題のform_forヘルパーは次のようになります。

=form_for :credit_card, :params => @result && @result.params[:credit_card],
:errors => @result && @result.errors.for(:credit_card),
:builder => ApplicationHelper::BraintreeFormBuilder,
:url => Braintree::TransparentRedirect.url,
:html => {:autocomplete => "off"} do |f|

関連する行はBraintree::TransparentRedirect.urlのようです-おそらくテスト環境では、これは切り捨てられる/関連するホスト情報を失いますか?そうではありません!テスト用にpage.htmlを出力すると、次のようになります。

<form accept-charset="UTF-8" action="https://sandbox.braintreegateway.com:443/merchants/XXX/transparent_redirect_requests" autocomplete="off" method="post">

では、フォームのアクション属性が明確に示しているように、テストがデータをsandbox.braintreegateway.comに投稿するのではなく、自分のサーバーで/ Merchants...をヒットしようとしているように見えるのはなぜですか?

また、テスト手順を手動で複製する(有効なデータをフォームに入力し、送信を押す)ことは、開発と本番の両方で機能します。

4

1 に答える 1

2

Rails integration tests send all requests to your rails app - the host portion of the URL is ignored.

You could probably do this with rspec request specs as long as you use a suitable capybara driver - the default Rack::Test has the same behaviour with respect to hosts, but something like Capybara-webkit or one of the selenium drivers might be different.

于 2012-04-12T15:51:20.180 に答える