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 \
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.