我在rspec中有一个请求测试,用于测试来自端点的几个可能的重定向,例如:
get registrations_path
expect(response).to redirect_to(new_registration_path)在一种情况下,我希望它不会重定向。有没有办法否定matcher redirect_to?或显式断言not_redirect的匹配器
我尝试过这样的变体,但没有成功:
expect(response).not_to redirect_to(nil)
expect(response).not_to redirect
expect(response).to not_redirect我确实有其他测试来测试非重定向response...but的细节,我希望这个高级测试可以充实一套重定向测试。
发布于 2020-11-21 04:22:02
这不像.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 302https://stackoverflow.com/questions/64936356
复制相似问题