2017-07-21 30 views
0

我正在尋找一個像下面那樣的nginx重寫調用在serverspec中創建一個測試(它將^/folder/file.json URL的請求重定向到@redirect_url變量):使用serverspec測試重定向

rewrite ^/folder/file.json <%= @redirect_url %> permanent; 

對於我正在更新的主廚食譜。不幸的是,從我在互聯網上能夠找到的信息來看,它強調我完全不瞭解nginx和serverspec術語,或者你無法做到這一點。有沒有人能夠幫助?

回答

2

您可以直接使用Ruby的Net :: HTTP

describe Net::HTTP.get_response(URI('http://localhost:port/path')) do 
    its(:code) { should eq '301' } 
    its(:msg) { should match 'Moved Permanently' } 
end 
檢查響應代碼
1

重定向severspec使用curl命令是這樣的:

redirect_url = "..." 
describe command("curl -I http://example.com/folder/file.json") do 
    its(:stdout) { should match(%r|HTTP/1.1 301 Moved Permanently|) } 
    its(:stdout) { should match(%r|Location: #{Regexp.escape(redirect_url)}|) } 
end