[rspec-users] route_to for ambiguous generation?

Clifford T. Matthews ctm at devctm.com
Tue Oct 13 10:27:41 EDT 2009

I like the new route_to matcher, but I can't use it for my root route,
since the route that is generated isn't the route that I pass in.
Specifically, my routes.rb has:

  map.resources :skills, :only => [:index, :show]
  map.root :controller => :skills, :action => :index, :conditions => { :method => :get }

So, '/' routes to SkillsController#index,
but { :controller => :skills, :action => :index }
generates '/skills', an acceptable synonym.

So instead of being able to write:

  { :get, '/' }.should route_to(:controller => 'skills', :action => 'index')

I had to write the old style

  params_from(:get, '/').should == { :controller => 'skills', :action => 'index' }

That works, but is inelegant.

I think I can code things up so that I could write:

  { :get, '/' }.should route_to(:controller => 'skills', :action => 'index').which_generates('/skills')

If I understand how things work, I'd just need to add a
#which_generates method Spec::Rails::Matchers::RouteTo, and have it
set up an ivar that is used in the @example.assert_routing invocation.
I'm having some trouble accessing GitHub right now.  Once it's back, I'll
try doing what I've described.

Anyone see a better solution that I'm overlooking?
Cliff Matthews <ctm at devctm.com>

More information about the rspec-users mailing list