我有一个测试控制器动作的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