我想利用rails 3.1rc4中的force_ssl
feature。測試RSpec Rails中的HTTPS(SSL)請求
class ApplicationController < ActionController::Base
force_ssl
end
問題是這打破了我現有RSpec控制器規格的大部分/全部。例如,此操作失敗:
describe "GET 'index'" do
it "renders the Start page" do
get :index
response.should render_template 'index'
end
end
渲染頁面,而不是響應是301重定向到https://test.host/
。
如何更改我的規格以模擬HTTPS GET/POST?
我是否必須手動更改每項測試,還是有更簡單的方法? (我知道我只能在生產中調用force_ssl
,但這並不理想,真的,我應該測試force_ssl
是否確實在預期時重定向到https://)
這不適用於RSpec 2.10。看到這裏:https:// github。com/rspec/rspec-rails/issues/534 –
我正在使用rspe 2.11.0,我總是收到以下錯誤消息:「未定義的方法'env'爲nil:NilClass」。 –
注意到這是用Rails-rspec 2.14和Devise 3.0.0修復的 https://github.com/rspec/rspec-rails/issues/534#issuecomment-21560832 –