我想利用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 –