コントローラアクションをテストするrspecテストがあります。コントローラのリダイレクトをRSpecでテストする
class SalesController < ApplicationController
def create
# This redirect sends the user to SalesController#go_to_home
redirect_to '/go_to_home'
end
def go_to_home
redirect_to '/'
end
end
マイコントローラーのテストは、私は、テストを実行すると
RSpec.describe SalesController, type: :controller do
include PathsHelper
describe 'POST create' do
post :create
expect(response).to redirect_to '/'
end
end
はしかし、それは私にそれを伝えるようになっています
Expected response to be a redirect to <http://test.host/> but was a redirect to <http://test.host/go_to_home>.
Expected "http://test.host/" to be === "http://test.host/go_to_home".
/go_to_home
がSalesController番号のgo_to_homeにユーザーを送信します。回答が最終的にURL http://test.host/
のホームページにつながることをテストするにはどうすればよいですか?
「/」に直接リダイレクトする
create
アクション私は私の質問を明確にします。 '/ go_to_home'はユーザーをSalesController#go_to_homeに送ります。 – jason328いいえ、私はSalesController#createからgo_to_homeだけを呼び出しています。理解するこの例を単純化して、多くのロジックが失われてしまった。 – jason328