[rspec-users] route_to for ambiguous generation?

Randy Harmon r_j_h_box-sf at yahoo.com
Tue Oct 13 10:54:05 EDT 2009


Hi Cliff,

Hey, that's a good use case - one I hadn't considered.  Just goes to
show you, the real world has a way of intruding on happy theories.  :) 
It's nice to hear feedback about the matcher.

which_generates() as a method on the route_to() matcher seems like it
should work to me, once it's written.  I don't generally wish to have
two separate paths to the same content for publicly-accessible sites,
because it's not as good for SEO, but there are certainly cases I can
think of where that's irrelevant.

I've had difficulty with my rspec-rails testing environment lately so
it'd be difficult for me to quickly make the adjustment, but it does
seem like it would be a simple change for someone who had strong
motivation or easy access.

Randy



On 10/13/09 7:27 AM, Clifford T. Matthews wrote:
> 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?
>   



More information about the rspec-users mailing list