How can I specify https protocol in routing spec with rspec?

守給你的承諾、 提交于 2019-12-05 08:07:37

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.

I'm not sure, but I think routes should be declared as plural — see Rails Routing from the Outside In. So it would be

resources :subscriptions

and in the spec

{:get => '/subscriptions', :protocol => 'https'}

Try if that passes without :protocol. If it does, skip the spec with HTTPS. That should not be tested on a unit-test level, but in an integration test.

Does it pass if you change to spec to this?:

{:get => '/subscription'}.should_not route_to(:controller => …)

That would at least give you the confidence that HTTP is not routed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!