[rspec-users] subdomain based namespacing makes RSpec incorrectly state that the route doesn't exist

Daniel dnelson77 at gmail.com
Thu Jun 9 12:03:57 EDT 2011


Hello,

I'm doing namespace routing based on subdomain, rather than path, so
that http://admin.example.com/pages leads to app/controllers/admin/
pages_controller.rb. Cucumber is following this fine, but RSpec is
complaining that the requested route doesn't exist even though "rake
routes" shows the route. When I add a standard namespace below the
"scope :admin" block in my routes.rb file, RSpec does recognize the
route, but I don't want path based namespacing.

The relevant parts of routes.rb, and the spec file follow below, along
with the the RSpec output and the matching line of "rake routes".

config/routes.rb:

scope :admin, :as => 'admin', :module => 'admin', :conditions =>
{ :subdomain => 'admin' } do
  resources :pages
end


spec/controllers/admin/pages_controller_spec.rb:

require 'spec_helper'
describe Admin::PagesController do
  describe "GET index" do
    context "while not signed-in" do
      it "should redirect to www.example.com" do
        get :index
        # also tried get :index, :subdomain => 'admin'
        response.should redirect_to(root_url(:subdomain => 'www'))
      end
    end
  end
end



$ rspec spec/controllers/admin/pages_controller_spec.rb
No DRb server is running. Running in local process instead ...
F

Failures:

  1) Admin::PagesController GET index while not signed-in should
redirect to www.example.com
     Failure/Error: get :index
     ActionController::RoutingError:
       No route matches {:controller=>"admin/pages"}


$ rake routes
...
admin_pages GET    /pages(.:format)
{:action=>"index", :controller=>"admin/pages"}
...


Thank you for any help you can offer,

Daniel


More information about the rspec-users mailing list