我需要检查 301 重定向。 所以我有应该重定向到新网址的旧网址。 验证它的最佳做法是什么? 现在我正在考虑简单的方法:导航到旧 URL 并检查新 URL 是否正确并显示相应的页面。我可以检查它是301重定向吗? 我找到了以下文章:http://www.natontesting.com/2010/09/06/announcing-responsalizr-test-http-response-codes-in-ruby/
但在重定向后我看到当前状态码 =200 有什么建议我怎样才能捕捉到 301 状态码?
提前致谢
最佳答案
不要在功能规范中这样做。在功能规范( cucumber )中,您测试网站用户如何看待它,用户不关心状态代码是什么。如果您真的关心响应,请在 Controller 或更好的请求规范中执行。使用 rspec,它可能看起来像这样:
describe 'redirects' do
context 'on GET /old_users' do
before do
get '/old_users'
end
it 'redirects /old_users to /users' do
expect(response).to redirect_to('/users')
end
it 'responds with a 301 - Permanently moved' do
expect(response.status).to eq(301)
end
end
end
https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
关于ruby - cucumber 、 Selenium 、 ruby : best practices to check 301 redirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20429813/