I am working on a Rails 3 application using RSPec 2.beta.20.
I am having the following routes in my routes.rb
routes.rb
resources :projects
root :to => ‘projects#index’
I am trying to test both the routes. But while testing root route I am
getting a failure :
it ‘should route root to projects#index’ do
{:get => ‘/’}.should route_to(:controller => ‘projects’, :action =>
‘index’)
end
But the above example is failing since route_to is expecting a route
like
‘/projects’. Is there a way to test root routes which are also
configured
elsewhere in the routes.rb.
Regards,
Amiruddin N.,
Bangalore, 560008, KA
India
it ‘should route root to projects#index’ do
{:get => ‘/’}.should route_to(:controller => ‘projects’, :action => ‘index’)
end
But the above example is failing since route_to is expecting a route like ‘/projects’. Is there a way to test root routes which are also configured elsewhere in the routes.rb.
route_to delegates to assert_routing, which only passes if both
assert_generates and assert_recognizes passes. There was a lengthy
thread about this [1] but we never resolved the API deficiency.
Obviously we need something before a final rspec-rails-2 release, but in
the mean time you can always use the built-in rails assertions. In this
case, you’d use: