Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" 
like image 286
morgan freeman Avatar asked Sep 06 '11 09:09

morgan freeman


1 Answers

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.

like image 134
John Bachir Avatar answered Nov 16 '22 05:11

John Bachir