此方法重定向到外部网站。我如何测试这种行为?我知道该方法可以正常工作,因为我在浏览器中进行了测试,但我无法通过测试。
def create
if @order.save
redirect_to Gateway.new(@order).send
else
render 'new'
end
end
我写了这个测试失败,出现“缺少模板错误”:
describe 'User creates an order with valid info' do
before do
WebMock.allow_net_connect!
stub_request(:any, "https://external-site.com/v2/checkout")
end
it 'creates the order and redirects to checkout page' do
fill_in_order
expect { click_button "Submit" }.to change(Order, :count)
end
end
错误:
Failure/Error: click_button "Submit"
ActionView::MissingTemplate:
Missing template orders/create, ...