Route_to to test root route

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

Y! IM : [email protected]
GTalk : [email protected]

On Sep 29, 2010, at 12:44 AM, Amiruddin N. wrote:

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:

assert_recognizes({:controller => “projects”, :action => “index”},
{:method => “get”, :path => “/”})

Cheers,
David

[1]
http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4bd3a78/2a60d77662a1ec31

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs