我剛剛已經瞭解了RSpec和Cabybara是多麼的酷,現在正在努力學習編寫實際測試。使用RSpec和Capybara測試重定向(Rails)
我想檢查點擊鏈接後,是否有重定向到特定頁面。 下面是場景
1) I have a page /projects/list - I have an anchor with html "Back" and it links to /projects/show Below is the test i wrote in rspec describe "Sample" do describe "GET /projects/list" do it "sample test" do visit "/projects/list" click_link "Back" assert_redirected_to "/projects/show" end end end
測試失敗,失敗消息像下面
Failure/Error: assert_redirected_to "/projects/show" ArgumentError: @request must be an ActionDispatch::Request
請給我建議,我應該如何測試的重定向和我到底做錯了什麼?
可能更好地使用'projects_path'?也許在你使用'expect'時使用'not''' – SuckerForMayhem