我有一個測試控制器動作的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。我如何測試該響應最終將導致主頁的網址爲http://test.host/
?
我會澄清我的問題。 '/ go_to_home'會將用戶發送到SalesController#go_to_home。 – jason328
不,我只從SalesController#create調用go_to_home。瞭解我已經簡化了這個例子,所以有很多邏輯缺失。 – jason328