Redirect Rspec:expect(请求)。是否不重定向?(重定向到的对面)

Redirect Rspec:expect(请求)。是否不重定向?(重定向到的对面),redirect,rspec,negate,Redirect,Rspec,Negate,我在rspec中有一个请求测试,它测试来自端点的几个潜在重定向,例如: get registrations_path expect(response).to redirect_to(new_registration_path) 在一种情况下,我希望它不会重定向。有没有办法取消匹配器的重定向到?或者显式断言不\u重定向的匹配器 我尝试过这样的变化,但没有成功: expect(response).not_to redirect_to(nil) expect(response).not_to red

我在rspec中有一个请求测试,它测试来自端点的几个潜在重定向,例如:

get registrations_path
expect(response).to redirect_to(new_registration_path)
在一种情况下,我希望它不会重定向。有没有办法取消匹配器的重定向到?或者显式断言
不\u重定向的匹配器

我尝试过这样的变化,但没有成功:

expect(response).not_to redirect_to(nil)
expect(response).not_to redirect
expect(response).to not_redirect

我确实有其他测试来测试非重定向响应的细节……但我希望这个高级别测试能够充实出一套重定向测试。

这并不像
那么严格。不重定向
,但至少要简明易懂:

it { expect(response).not_to have_http_status(:redirect) }
当测试失败时,它会给出有用的响应:

 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