How to test for a redirect with Rspec and Capybara

后端 未结 5 756
予麋鹿
予麋鹿 2021-01-01 13:11

I don\'t know what I\'m doing wrong, but every time I try to test for a redirect, I get this error: \"@request must be an ActionDispatch::Request\"

context \         


        
5条回答
  •  难免孤独
    2021-01-01 13:50

    The error message @request must be an ActionDispatch::Request tells you that rspec-rails matcher redirect_to (it delegates to Rails assert_redirected_to) expects it to be used in Rails functional tests (should mix in ActionController::TestCase). The code you posted looks like rspec-rails request spec. So redirect_to is not available.

    Checking for redirect is not supported in rspec-rails request specs, but is supported in Rails integration tests.

    Whether you should explicitly check for how redirect was made (that it is was a 301 response and not a 307 response and not some javascript) is completely up to you.

提交回复
热议问题