Reputation: 6287
I've got a request test in rspec that tests for several potential redirects from an endpoint, such as:
get registrations_path
expect(response).to redirect_to(new_registration_path)
In one case, I expect it to not redirect. Is there a way to negate the matcher redirect_to
? Or a matcher that explicitly asserts not_redirect
?
I've tried variations such as these, without success:
expect(response).not_to redirect_to(nil)
expect(response).not_to redirect
expect(response).to not_redirect
I do have other tests that test for specifics of a non-redirecting response...but I want this high-level test to flesh out a suite of redirect tests.
Upvotes: 1
Views: 1312
Reputation: 6287
This isn't quite as tight as .to not_redirect
, but is at least concise and obvious to understand:
it { expect(response).not_to have_http_status(:redirect) }
When the test fails, it gives a useful response:
1. Failure/Error: expect(response).not_to have_http_status(:redirect)
expected the response not to have a redirect status code (3xx) but it was 302
Upvotes: 1