如何使用 rspec 在路由规范中指定 https 协议? [英] How can I specify https protocol in routing spec with rspec?
本文介绍了如何使用 rspec 在路由规范中指定 https 协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的路线文件中,我有:
resources :subscription, :only =>[:show], :constraints =>{:协议=>"https"}
我正在尝试为这条路线添加一个规范,如下所示:
它识别并生成#show"做{ :get =>"/订阅", :protocol =>'https' }..should route_to(:controller => "subscriptions", :action => "show")结尾
然而,规范仍然失败.如果我删除 :protocol =>'https'
,规范也失败了:
解决方案
(未记录的?)解决方案是简单地包含一个完整的虚拟 url,如下所示:
它识别并生成#show"做{ :get =>"https://test.host/subscription" }.should route_to(:controller => "subscriptions", :action => "show")结尾
In my routes file I have:
resources :subscription, :only => [:show], :constraints => {:protocol => "https"}
I'm trying to add a spec for this route like this:
it "recognizes and generates #show" do
{ :get => "/subscription", :protocol => 'https' }.should route_to(:controller => "subscriptions", :action => "show")
end
However, the spec still fails.
If I remove the :protocol => 'https'
, the spec also fails:
ActionController::RoutingError: No route matches "/subscription"
解决方案
The (undocumented?) solution is to simply include an entire dummy url, like so:
it "recognizes and generates #show" do
{ :get => "https://test.host/subscription" }.should route_to(:controller => "subscriptions", :action => "show")
end
I figured it out from this ticket and this changeset.
这篇关于如何使用 rspec 在路由规范中指定 https 协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文