Search code examples
ruby-on-railsrspecrspec-railsspecifications

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" 

Solution

  • 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.